Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / mscorlib / system / io / textwriter.cs
blob8b0c7b5a61fbb141fde88fbf0b98d43f5667c6ba
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 /*============================================================
7 **
8 ** Class: TextWriter
9 **
10 ** <OWNER>Microsoft</OWNER>
13 ** Purpose: Abstract base class for Text-only Writers.
14 ** Subclasses will include StreamWriter & StringWriter.
17 ===========================================================*/
19 using System;
20 using System.Text;
21 using System.Threading;
22 using System.Runtime.CompilerServices;
23 using System.Runtime.InteropServices;
24 using System.Reflection;
25 using System.Security.Permissions;
26 using System.Globalization;
27 using System.Diagnostics.CodeAnalysis;
28 using System.Diagnostics.Contracts;
29 #if FEATURE_ASYNC_IO
30 using System.Threading.Tasks;
31 #endif
33 namespace System.IO {
34 // This abstract base class represents a writer that can write a sequential
35 // stream of characters. A subclass must minimally implement the
36 // Write(char) method.
38 // This class is intended for character output, not bytes.
39 // There are methods on the Stream class for writing bytes.
40 [Serializable]
41 [ComVisible(true)]
42 #if FEATURE_REMOTING || MONO
43 public abstract class TextWriter : MarshalByRefObject, IDisposable {
44 #else // FEATURE_REMOTING
45 public abstract class TextWriter : IDisposable {
46 #endif // FEATURE_REMOTING
47 public static readonly TextWriter Null = new NullTextWriter();
49 #if FEATURE_ASYNC_IO
50 [NonSerialized]
51 private static Action<object> _WriteCharDelegate = state =>
53 Tuple<TextWriter, char> tuple = (Tuple<TextWriter, char>)state;
54 tuple.Item1.Write(tuple.Item2);
57 [NonSerialized]
58 private static Action<object> _WriteStringDelegate = state =>
60 Tuple<TextWriter, string> tuple = (Tuple<TextWriter, string>)state;
61 tuple.Item1.Write(tuple.Item2);
64 [NonSerialized]
65 private static Action<object> _WriteCharArrayRangeDelegate = state =>
67 Tuple<TextWriter, char[], int, int> tuple = (Tuple<TextWriter, char[],int, int>)state;
68 tuple.Item1.Write(tuple.Item2, tuple.Item3, tuple.Item4);
71 [NonSerialized]
72 private static Action<object> _WriteLineCharDelegate = state =>
74 Tuple<TextWriter, char> tuple = (Tuple<TextWriter, char>)state;
75 tuple.Item1.WriteLine(tuple.Item2);
78 [NonSerialized]
79 private static Action<object> _WriteLineStringDelegate = state =>
81 Tuple<TextWriter, string> tuple = (Tuple<TextWriter, string>)state;
82 tuple.Item1.WriteLine(tuple.Item2);
85 [NonSerialized]
86 private static Action<object> _WriteLineCharArrayRangeDelegate = state =>
88 Tuple<TextWriter, char[], int, int> tuple = (Tuple<TextWriter, char[],int, int>)state;
89 tuple.Item1.WriteLine(tuple.Item2, tuple.Item3, tuple.Item4);
92 [NonSerialized]
93 private static Action<object> _FlushDelegate = state => ((TextWriter)state).Flush();
94 #endif
96 // This should be initialized to Environment.NewLine, but
97 // to avoid loading Environment unnecessarily so I've duplicated
98 // the value here.
99 #if MONO
100 static string InitialNewLine {
101 get {
102 return Environment.NewLine;
106 protected char[] CoreNewLine = InitialNewLine.ToCharArray ();
107 #else
109 private const String InitialNewLine = "\r\n";
111 protected char[] CoreNewLine = new char[] { '\r', '\n' };
112 #endif
114 // Can be null - if so, ask for the Thread's CurrentCulture every time.
115 private IFormatProvider InternalFormatProvider;
117 protected TextWriter()
119 InternalFormatProvider = null; // Ask for CurrentCulture all the time.
122 protected TextWriter(IFormatProvider formatProvider)
124 InternalFormatProvider = formatProvider;
127 public virtual IFormatProvider FormatProvider {
128 get {
129 if (InternalFormatProvider == null)
130 return Thread.CurrentThread.CurrentCulture;
131 else
132 return InternalFormatProvider;
136 // Closes this TextWriter and releases any system resources associated with the
137 // TextWriter. Following a call to Close, any operations on the TextWriter
138 // may raise exceptions. This default method is empty, but descendant
139 // classes can override the method to provide the appropriate
140 // functionality.
141 public virtual void Close() {
142 Dispose(true);
143 GC.SuppressFinalize(this);
146 protected virtual void Dispose(bool disposing)
151 public void Dispose()
153 Dispose(true);
154 GC.SuppressFinalize(this);
157 // Clears all buffers for this TextWriter and causes any buffered data to be
158 // written to the underlying device. This default method is empty, but
159 // descendant classes can override the method to provide the appropriate
160 // functionality.
161 public virtual void Flush() {
164 public abstract Encoding Encoding {
165 get;
168 // Returns the line terminator string used by this TextWriter. The default line
169 // terminator string is a carriage return followed by a line feed ("\r\n").
171 // Sets the line terminator string for this TextWriter. The line terminator
172 // string is written to the text stream whenever one of the
173 // WriteLine methods are called. In order for text written by
174 // the TextWriter to be readable by a TextReader, only one of the following line
175 // terminator strings should be used: "\r", "\n", or "\r\n".
177 public virtual String NewLine {
178 get { return new String(CoreNewLine); }
179 set {
180 if (value == null)
181 value = InitialNewLine;
182 CoreNewLine = value.ToCharArray();
187 [HostProtection(Synchronization=true)]
188 public static TextWriter Synchronized(TextWriter writer) {
189 if (writer==null)
190 throw new ArgumentNullException("writer");
191 Contract.Ensures(Contract.Result<TextWriter>() != null);
192 Contract.EndContractBlock();
194 if (writer is SyncTextWriter)
195 return writer;
197 return new SyncTextWriter(writer);
200 // Writes a character to the text stream. This default method is empty,
201 // but descendant classes can override the method to provide the
202 // appropriate functionality.
204 public virtual void Write(char value) {
207 // Writes a character array to the text stream. This default method calls
208 // Write(char) for each of the characters in the character array.
209 // If the character array is null, nothing is written.
211 public virtual void Write(char[] buffer) {
212 if (buffer != null) Write(buffer, 0, buffer.Length);
215 // Writes a range of a character array to the text stream. This method will
216 // write count characters of data into this TextWriter from the
217 // buffer character array starting at position index.
219 public virtual void Write(char[] buffer, int index, int count) {
220 if (buffer==null)
221 throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
222 if (index < 0)
223 throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
224 if (count < 0)
225 throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
226 if (buffer.Length - index < count)
227 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
228 Contract.EndContractBlock();
230 for (int i = 0; i < count; i++) Write(buffer[index + i]);
233 // Writes the text representation of a boolean to the text stream. This
234 // method outputs either Boolean.TrueString or Boolean.FalseString.
236 public virtual void Write(bool value) {
237 Write(value ? Boolean.TrueLiteral : Boolean.FalseLiteral);
240 // Writes the text representation of an integer to the text stream. The
241 // text representation of the given value is produced by calling the
242 // Int32.ToString() method.
244 public virtual void Write(int value) {
245 Write(value.ToString(FormatProvider));
248 // Writes the text representation of an integer to the text stream. The
249 // text representation of the given value is produced by calling the
250 // UInt32.ToString() method.
252 [CLSCompliant(false)]
253 public virtual void Write(uint value) {
254 Write(value.ToString(FormatProvider));
257 // Writes the text representation of a long to the text stream. The
258 // text representation of the given value is produced by calling the
259 // Int64.ToString() method.
261 public virtual void Write(long value) {
262 Write(value.ToString(FormatProvider));
265 // Writes the text representation of an unsigned long to the text
266 // stream. The text representation of the given value is produced
267 // by calling the UInt64.ToString() method.
269 [CLSCompliant(false)]
270 public virtual void Write(ulong value) {
271 Write(value.ToString(FormatProvider));
274 // Writes the text representation of a float to the text stream. The
275 // text representation of the given value is produced by calling the
276 // Float.toString(float) method.
278 public virtual void Write(float value) {
279 Write(value.ToString(FormatProvider));
282 // Writes the text representation of a double to the text stream. The
283 // text representation of the given value is produced by calling the
284 // Double.toString(double) method.
286 public virtual void Write(double value) {
287 Write(value.ToString(FormatProvider));
290 public virtual void Write(Decimal value) {
291 Write(value.ToString(FormatProvider));
294 // Writes a string to the text stream. If the given string is null, nothing
295 // is written to the text stream.
297 public virtual void Write(String value) {
298 if (value != null) Write(value.ToCharArray());
301 // Writes the text representation of an object to the text stream. If the
302 // given object is null, nothing is written to the text stream.
303 // Otherwise, the object's ToString method is called to produce the
304 // string representation, and the resulting string is then written to the
305 // output stream.
307 public virtual void Write(Object value) {
308 if (value != null) {
309 IFormattable f = value as IFormattable;
310 if (f != null)
311 Write(f.ToString(null, FormatProvider));
312 else
313 Write(value.ToString());
317 #if false
318 // // Converts the wchar * to a string and writes this to the stream.
319 // //
320 // __attribute NonCLSCompliantAttribute()
321 // public void Write(wchar *value) {
322 // Write(new String(value));
323 // }
325 // // Treats the byte* as a LPCSTR, converts it to a string, and writes it to the stream.
326 // //
327 // __attribute NonCLSCompliantAttribute()
328 // public void Write(byte *value) {
329 // Write(new String(value));
330 // }
331 #endif
334 // Writes out a formatted string. Uses the same semantics as
335 // String.Format.
337 public virtual void Write(String format, Object arg0)
339 Write(String.Format(FormatProvider, format, arg0));
342 // Writes out a formatted string. Uses the same semantics as
343 // String.Format.
345 public virtual void Write(String format, Object arg0, Object arg1)
347 Write(String.Format(FormatProvider, format, arg0, arg1));
350 // Writes out a formatted string. Uses the same semantics as
351 // String.Format.
353 public virtual void Write(String format, Object arg0, Object arg1, Object arg2)
355 Write(String.Format(FormatProvider, format, arg0, arg1, arg2));
358 // Writes out a formatted string. Uses the same semantics as
359 // String.Format.
361 public virtual void Write(String format, params Object[] arg)
363 Write(String.Format(FormatProvider, format, arg));
367 // Writes a line terminator to the text stream. The default line terminator
368 // is a carriage return followed by a line feed ("\r\n"), but this value
369 // can be changed by setting the NewLine property.
371 public virtual void WriteLine() {
372 Write(CoreNewLine);
375 // Writes a character followed by a line terminator to the text stream.
377 public virtual void WriteLine(char value) {
378 Write(value);
379 WriteLine();
382 // Writes an array of characters followed by a line terminator to the text
383 // stream.
385 public virtual void WriteLine(char[] buffer) {
386 Write(buffer);
387 WriteLine();
390 // Writes a range of a character array followed by a line terminator to the
391 // text stream.
393 public virtual void WriteLine(char[] buffer, int index, int count) {
394 Write(buffer, index, count);
395 WriteLine();
398 // Writes the text representation of a boolean followed by a line
399 // terminator to the text stream.
401 public virtual void WriteLine(bool value) {
402 Write(value);
403 WriteLine();
406 // Writes the text representation of an integer followed by a line
407 // terminator to the text stream.
409 public virtual void WriteLine(int value) {
410 Write(value);
411 WriteLine();
414 // Writes the text representation of an unsigned integer followed by
415 // a line terminator to the text stream.
417 [CLSCompliant(false)]
418 public virtual void WriteLine(uint value) {
419 Write(value);
420 WriteLine();
423 // Writes the text representation of a long followed by a line terminator
424 // to the text stream.
426 public virtual void WriteLine(long value) {
427 Write(value);
428 WriteLine();
431 // Writes the text representation of an unsigned long followed by
432 // a line terminator to the text stream.
434 [CLSCompliant(false)]
435 public virtual void WriteLine(ulong value) {
436 Write(value);
437 WriteLine();
440 // Writes the text representation of a float followed by a line terminator
441 // to the text stream.
443 public virtual void WriteLine(float value) {
444 Write(value);
445 WriteLine();
448 // Writes the text representation of a double followed by a line terminator
449 // to the text stream.
451 public virtual void WriteLine(double value) {
452 Write(value);
453 WriteLine();
456 public virtual void WriteLine(decimal value) {
457 Write(value);
458 WriteLine();
461 // Writes a string followed by a line terminator to the text stream.
463 public virtual void WriteLine(String value) {
465 if (value==null) {
466 WriteLine();
468 else {
469 // We'd ideally like WriteLine to be atomic, in that one call
470 // to WriteLine equals one call to the OS (ie, so writing to
471 // console while simultaneously calling printf will guarantee we
472 // write out a string and new line chars, without any interference).
473 // Additionally, we need to call ToCharArray on Strings anyways,
474 // so allocating a char[] here isn't any worse than what we were
475 // doing anyways. We do reduce the number of calls to the
476 // backing store this way, potentially.
477 int vLen = value.Length;
478 int nlLen = CoreNewLine.Length;
479 char[] chars = new char[vLen+nlLen];
480 value.CopyTo(0, chars, 0, vLen);
481 // CoreNewLine will almost always be 2 chars, and possibly 1.
482 if (nlLen == 2) {
483 chars[vLen] = CoreNewLine[0];
484 chars[vLen+1] = CoreNewLine[1];
486 else if (nlLen == 1)
487 chars[vLen] = CoreNewLine[0];
488 else
489 Buffer.InternalBlockCopy(CoreNewLine, 0, chars, vLen * 2, nlLen * 2);
490 Write(chars, 0, vLen + nlLen);
493 Write(value); // We could call Write(String) on StreamWriter...
494 WriteLine();
498 // Writes the text representation of an object followed by a line
499 // terminator to the text stream.
501 public virtual void WriteLine(Object value) {
502 if (value==null) {
503 WriteLine();
505 else {
506 // Call WriteLine(value.ToString), not Write(Object), WriteLine().
507 // This makes calls to WriteLine(Object) atomic.
508 IFormattable f = value as IFormattable;
509 if (f != null)
510 WriteLine(f.ToString(null, FormatProvider));
511 else
512 WriteLine(value.ToString());
516 // Writes out a formatted string and a new line. Uses the same
517 // semantics as String.Format.
519 public virtual void WriteLine(String format, Object arg0)
521 WriteLine(String.Format(FormatProvider, format, arg0));
524 // Writes out a formatted string and a new line. Uses the same
525 // semantics as String.Format.
527 public virtual void WriteLine (String format, Object arg0, Object arg1)
529 WriteLine(String.Format(FormatProvider, format, arg0, arg1));
532 // Writes out a formatted string and a new line. Uses the same
533 // semantics as String.Format.
535 public virtual void WriteLine (String format, Object arg0, Object arg1, Object arg2)
537 WriteLine(String.Format(FormatProvider, format, arg0, arg1, arg2));
540 // Writes out a formatted string and a new line. Uses the same
541 // semantics as String.Format.
543 public virtual void WriteLine (String format, params Object[] arg)
545 WriteLine(String.Format(FormatProvider, format, arg));
548 #if FEATURE_ASYNC_IO
549 #region Task based Async APIs
550 [HostProtection(ExternalThreading = true)]
551 [ComVisible(false)]
552 public virtual Task WriteAsync(char value)
554 Tuple<TextWriter, char> tuple = new Tuple<TextWriter, char>(this, value);
555 return Task.Factory.StartNew(_WriteCharDelegate, tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
558 [HostProtection(ExternalThreading = true)]
559 [ComVisible(false)]
560 public virtual Task WriteAsync(String value)
562 Tuple<TextWriter, string> tuple = new Tuple<TextWriter, string>(this, value);
563 return Task.Factory.StartNew(_WriteStringDelegate, tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
566 [HostProtection(ExternalThreading = true)]
567 [ComVisible(false)]
568 public Task WriteAsync(char[] buffer)
570 if (buffer == null) return Task.CompletedTask;
571 return WriteAsync(buffer, 0, buffer.Length);
574 [HostProtection(ExternalThreading = true)]
575 [ComVisible(false)]
576 public virtual Task WriteAsync(char[] buffer, int index, int count)
578 Tuple<TextWriter, char[], int, int> tuple = new Tuple<TextWriter, char[], int, int>(this, buffer, index, count);
579 return Task.Factory.StartNew(_WriteCharArrayRangeDelegate, tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
582 [HostProtection(ExternalThreading = true)]
583 [ComVisible(false)]
584 public virtual Task WriteLineAsync(char value)
586 Tuple<TextWriter, char> tuple = new Tuple<TextWriter, char>(this, value);
587 return Task.Factory.StartNew(_WriteLineCharDelegate, tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
590 [HostProtection(ExternalThreading = true)]
591 [ComVisible(false)]
592 public virtual Task WriteLineAsync(String value)
594 Tuple<TextWriter, string> tuple = new Tuple<TextWriter, string>(this, value);
595 return Task.Factory.StartNew(_WriteLineStringDelegate, tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
598 [HostProtection(ExternalThreading = true)]
599 [ComVisible(false)]
600 public Task WriteLineAsync(char[] buffer)
602 if (buffer == null) return Task.CompletedTask;
603 return WriteLineAsync(buffer, 0, buffer.Length);
606 [HostProtection(ExternalThreading = true)]
607 [ComVisible(false)]
608 public virtual Task WriteLineAsync(char[] buffer, int index, int count)
610 Tuple<TextWriter, char[], int, int> tuple = new Tuple<TextWriter, char[], int, int>(this, buffer, index, count);
611 return Task.Factory.StartNew(_WriteLineCharArrayRangeDelegate, tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
614 [HostProtection(ExternalThreading = true)]
615 [ComVisible(false)]
616 public virtual Task WriteLineAsync()
618 return WriteAsync(CoreNewLine);
621 [HostProtection(ExternalThreading = true)]
622 [ComVisible(false)]
623 public virtual Task FlushAsync()
625 return Task.Factory.StartNew(_FlushDelegate, this, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
627 #endregion
628 #endif //FEATURE_ASYNC_IO
630 [Serializable]
631 private sealed class NullTextWriter : TextWriter
633 internal NullTextWriter(): base(CultureInfo.InvariantCulture) {
636 public override Encoding Encoding {
637 get { return Encoding.Default; }
640 [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
641 public override void Write(char[] buffer, int index, int count) {
644 public override void Write(String value) {
647 // Not strictly necessary, but for perf reasons
648 public override void WriteLine() {
651 // Not strictly necessary, but for perf reasons
652 public override void WriteLine(String value) {
655 public override void WriteLine(Object value) {
659 [Serializable]
660 internal sealed class SyncTextWriter : TextWriter, IDisposable
662 private TextWriter _out;
664 internal SyncTextWriter(TextWriter t): base(t.FormatProvider) {
665 _out = t;
668 public override Encoding Encoding {
669 get { return _out.Encoding; }
672 public override IFormatProvider FormatProvider {
673 get { return _out.FormatProvider; }
676 public override String NewLine {
677 [MethodImplAttribute(MethodImplOptions.Synchronized)]
678 get { return _out.NewLine; }
679 [MethodImplAttribute(MethodImplOptions.Synchronized)]
680 set { _out.NewLine = value; }
683 [MethodImplAttribute(MethodImplOptions.Synchronized)]
684 public override void Close() {
685 // So that any overriden Close() gets run
686 _out.Close();
689 [MethodImplAttribute(MethodImplOptions.Synchronized)]
690 protected override void Dispose(bool disposing) {
691 // Explicitly pick up a potentially methodimpl'ed Dispose
692 if (disposing)
693 ((IDisposable)_out).Dispose();
696 [MethodImplAttribute(MethodImplOptions.Synchronized)]
697 public override void Flush() {
698 _out.Flush();
701 [MethodImplAttribute(MethodImplOptions.Synchronized)]
702 public override void Write(char value) {
703 _out.Write(value);
706 [MethodImplAttribute(MethodImplOptions.Synchronized)]
707 public override void Write(char[] buffer) {
708 _out.Write(buffer);
711 [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
712 [MethodImplAttribute(MethodImplOptions.Synchronized)]
713 public override void Write(char[] buffer, int index, int count) {
714 _out.Write(buffer, index, count);
717 [MethodImplAttribute(MethodImplOptions.Synchronized)]
718 public override void Write(bool value) {
719 _out.Write(value);
722 [MethodImplAttribute(MethodImplOptions.Synchronized)]
723 public override void Write(int value) {
724 _out.Write(value);
727 [MethodImplAttribute(MethodImplOptions.Synchronized)]
728 public override void Write(uint value) {
729 _out.Write(value);
732 [MethodImplAttribute(MethodImplOptions.Synchronized)]
733 public override void Write(long value) {
734 _out.Write(value);
737 [MethodImplAttribute(MethodImplOptions.Synchronized)]
738 public override void Write(ulong value) {
739 _out.Write(value);
742 [MethodImplAttribute(MethodImplOptions.Synchronized)]
743 public override void Write(float value) {
744 _out.Write(value);
747 [MethodImplAttribute(MethodImplOptions.Synchronized)]
748 public override void Write(double value) {
749 _out.Write(value);
752 [MethodImplAttribute(MethodImplOptions.Synchronized)]
753 public override void Write(Decimal value) {
754 _out.Write(value);
757 [MethodImplAttribute(MethodImplOptions.Synchronized)]
758 public override void Write(String value) {
759 _out.Write(value);
762 [MethodImplAttribute(MethodImplOptions.Synchronized)]
763 public override void Write(Object value) {
764 _out.Write(value);
767 [MethodImplAttribute(MethodImplOptions.Synchronized)]
768 public override void Write(String format, Object arg0) {
769 _out.Write(format, arg0);
772 [MethodImplAttribute(MethodImplOptions.Synchronized)]
773 public override void Write(String format, Object arg0, Object arg1) {
774 _out.Write(format, arg0, arg1);
777 [MethodImplAttribute(MethodImplOptions.Synchronized)]
778 public override void Write(String format, Object arg0, Object arg1, Object arg2) {
779 _out.Write(format, arg0, arg1, arg2);
782 [MethodImplAttribute(MethodImplOptions.Synchronized)]
783 public override void Write(String format, Object[] arg) {
784 _out.Write(format, arg);
787 [MethodImplAttribute(MethodImplOptions.Synchronized)]
788 public override void WriteLine() {
789 _out.WriteLine();
792 [MethodImplAttribute(MethodImplOptions.Synchronized)]
793 public override void WriteLine(char value) {
794 _out.WriteLine(value);
797 [MethodImplAttribute(MethodImplOptions.Synchronized)]
798 public override void WriteLine(decimal value) {
799 _out.WriteLine(value);
802 [MethodImplAttribute(MethodImplOptions.Synchronized)]
803 public override void WriteLine(char[] buffer) {
804 _out.WriteLine(buffer);
807 [MethodImplAttribute(MethodImplOptions.Synchronized)]
808 public override void WriteLine(char[] buffer, int index, int count) {
809 _out.WriteLine(buffer, index, count);
812 [MethodImplAttribute(MethodImplOptions.Synchronized)]
813 public override void WriteLine(bool value) {
814 _out.WriteLine(value);
817 [MethodImplAttribute(MethodImplOptions.Synchronized)]
818 public override void WriteLine(int value) {
819 _out.WriteLine(value);
822 [MethodImplAttribute(MethodImplOptions.Synchronized)]
823 public override void WriteLine(uint value) {
824 _out.WriteLine(value);
827 [MethodImplAttribute(MethodImplOptions.Synchronized)]
828 public override void WriteLine(long value) {
829 _out.WriteLine(value);
832 [MethodImplAttribute(MethodImplOptions.Synchronized)]
833 public override void WriteLine(ulong value) {
834 _out.WriteLine(value);
837 [MethodImplAttribute(MethodImplOptions.Synchronized)]
838 public override void WriteLine(float value) {
839 _out.WriteLine(value);
842 [MethodImplAttribute(MethodImplOptions.Synchronized)]
843 public override void WriteLine(double value) {
844 _out.WriteLine(value);
847 [MethodImplAttribute(MethodImplOptions.Synchronized)]
848 public override void WriteLine(String value) {
849 _out.WriteLine(value);
852 [MethodImplAttribute(MethodImplOptions.Synchronized)]
853 public override void WriteLine(Object value) {
854 _out.WriteLine(value);
857 [MethodImplAttribute(MethodImplOptions.Synchronized)]
858 public override void WriteLine(String format, Object arg0) {
859 _out.WriteLine(format, arg0);
862 [MethodImplAttribute(MethodImplOptions.Synchronized)]
863 public override void WriteLine(String format, Object arg0, Object arg1) {
864 _out.WriteLine(format, arg0, arg1);
867 [MethodImplAttribute(MethodImplOptions.Synchronized)]
868 public override void WriteLine(String format, Object arg0, Object arg1, Object arg2) {
869 _out.WriteLine(format, arg0, arg1, arg2);
872 [MethodImplAttribute(MethodImplOptions.Synchronized)]
873 public override void WriteLine(String format, Object[] arg) {
874 _out.WriteLine(format, arg);
877 #if FEATURE_ASYNC_IO
880 // On SyncTextWriter all APIs should run synchronously, even the async ones.
883 [MethodImplAttribute(MethodImplOptions.Synchronized)]
884 [ComVisible(false)]
885 public override Task WriteAsync(char value)
887 Write(value);
888 return Task.CompletedTask;
891 [MethodImplAttribute(MethodImplOptions.Synchronized)]
892 [ComVisible(false)]
893 public override Task WriteAsync(String value)
895 Write(value);
896 return Task.CompletedTask;
899 [MethodImplAttribute(MethodImplOptions.Synchronized)]
900 [ComVisible(false)]
901 public override Task WriteAsync(char[] buffer, int index, int count)
903 Write(buffer, index, count);
904 return Task.CompletedTask;
907 [MethodImplAttribute(MethodImplOptions.Synchronized)]
908 [ComVisible(false)]
909 public override Task WriteLineAsync(char value)
911 WriteLine(value);
912 return Task.CompletedTask;
915 [MethodImplAttribute(MethodImplOptions.Synchronized)]
916 [ComVisible(false)]
917 public override Task WriteLineAsync(String value)
919 WriteLine(value);
920 return Task.CompletedTask;
923 [MethodImplAttribute(MethodImplOptions.Synchronized)]
924 [ComVisible(false)]
925 public override Task WriteLineAsync(char[] buffer, int index, int count)
927 WriteLine(buffer, index, count);
928 return Task.CompletedTask;
931 [MethodImplAttribute(MethodImplOptions.Synchronized)]
932 [ComVisible(false)]
933 public override Task FlushAsync()
935 Flush();
936 return Task.CompletedTask;
938 #endif //FEATURE_ASYNC_IO