3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 /*============================================================
10 ** <OWNER>Microsoft</OWNER>
13 ** Purpose: Abstract base class for Text-only Writers.
14 ** Subclasses will include StreamWriter & StringWriter.
17 ===========================================================*/
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
;
30 using System
.Threading
.Tasks
;
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.
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();
51 private static Action
<object> _WriteCharDelegate
= state
=>
53 Tuple
<TextWriter
, char> tuple
= (Tuple
<TextWriter
, char>)state
;
54 tuple
.Item1
.Write(tuple
.Item2
);
58 private static Action
<object> _WriteStringDelegate
= state
=>
60 Tuple
<TextWriter
, string> tuple
= (Tuple
<TextWriter
, string>)state
;
61 tuple
.Item1
.Write(tuple
.Item2
);
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
);
72 private static Action
<object> _WriteLineCharDelegate
= state
=>
74 Tuple
<TextWriter
, char> tuple
= (Tuple
<TextWriter
, char>)state
;
75 tuple
.Item1
.WriteLine(tuple
.Item2
);
79 private static Action
<object> _WriteLineStringDelegate
= state
=>
81 Tuple
<TextWriter
, string> tuple
= (Tuple
<TextWriter
, string>)state
;
82 tuple
.Item1
.WriteLine(tuple
.Item2
);
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
);
93 private static Action
<object> _FlushDelegate
= state
=> ((TextWriter
)state
).Flush();
96 // This should be initialized to Environment.NewLine, but
97 // to avoid loading Environment unnecessarily so I've duplicated
100 static string InitialNewLine
{
102 return Environment
.NewLine
;
106 protected char[] CoreNewLine
= InitialNewLine
.ToCharArray ();
109 private const String InitialNewLine
= "\r\n";
111 protected char[] CoreNewLine
= new char[] { '\r', '\n' }
;
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
{
129 if (InternalFormatProvider
== null)
130 return Thread
.CurrentThread
.CurrentCulture
;
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
141 public virtual void Close() {
143 GC
.SuppressFinalize(this);
146 protected virtual void Dispose(bool disposing
)
151 public void Dispose()
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
161 public virtual void Flush() {
164 public abstract Encoding Encoding
{
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); }
181 value = InitialNewLine
;
182 CoreNewLine
= value.ToCharArray();
187 [HostProtection(Synchronization
=true)]
188 public static TextWriter
Synchronized(TextWriter writer
) {
190 throw new ArgumentNullException("writer");
191 Contract
.Ensures(Contract
.Result
<TextWriter
>() != null);
192 Contract
.EndContractBlock();
194 if (writer
is SyncTextWriter
)
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
) {
221 throw new ArgumentNullException("buffer", Environment
.GetResourceString("ArgumentNull_Buffer"));
223 throw new ArgumentOutOfRangeException("index", Environment
.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
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
307 public virtual void Write(Object
value) {
309 IFormattable f
= value as IFormattable
;
311 Write(f
.ToString(null, FormatProvider
));
313 Write(value.ToString());
318 // // Converts the wchar * to a string and writes this to the stream.
320 // __attribute NonCLSCompliantAttribute()
321 // public void Write(wchar *value) {
322 // Write(new String(value));
325 // // Treats the byte* as a LPCSTR, converts it to a string, and writes it to the stream.
327 // __attribute NonCLSCompliantAttribute()
328 // public void Write(byte *value) {
329 // Write(new String(value));
334 // Writes out a formatted string. Uses the same semantics as
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
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
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
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() {
375 // Writes a character followed by a line terminator to the text stream.
377 public virtual void WriteLine(char value) {
382 // Writes an array of characters followed by a line terminator to the text
385 public virtual void WriteLine(char[] buffer
) {
390 // Writes a range of a character array followed by a line terminator to the
393 public virtual void WriteLine(char[] buffer
, int index
, int count
) {
394 Write(buffer
, index
, count
);
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) {
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) {
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) {
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) {
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) {
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) {
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) {
456 public virtual void WriteLine(decimal value) {
461 // Writes a string followed by a line terminator to the text stream.
463 public virtual void WriteLine(String
value) {
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.
483 chars
[vLen
] = CoreNewLine
[0];
484 chars
[vLen
+1] = CoreNewLine
[1];
487 chars
[vLen
] = CoreNewLine
[0];
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...
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) {
506 // Call WriteLine(value.ToString), not Write(Object), WriteLine().
507 // This makes calls to WriteLine(Object) atomic.
508 IFormattable f
= value as IFormattable
;
510 WriteLine(f
.ToString(null, FormatProvider
));
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
));
549 #region Task based Async APIs
550 [HostProtection(ExternalThreading
= true)]
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)]
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)]
568 public Task
WriteAsync(char[] buffer
)
570 if (buffer
== null) return Task
.CompletedTask
;
571 return WriteAsync(buffer
, 0, buffer
.Length
);
574 [HostProtection(ExternalThreading
= true)]
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)]
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)]
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)]
600 public Task
WriteLineAsync(char[] buffer
)
602 if (buffer
== null) return Task
.CompletedTask
;
603 return WriteLineAsync(buffer
, 0, buffer
.Length
);
606 [HostProtection(ExternalThreading
= true)]
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)]
616 public virtual Task
WriteLineAsync()
618 return WriteAsync(CoreNewLine
);
621 [HostProtection(ExternalThreading
= true)]
623 public virtual Task
FlushAsync()
625 return Task
.Factory
.StartNew(_FlushDelegate
, this, CancellationToken
.None
, TaskCreationOptions
.DenyChildAttach
, TaskScheduler
.Default
);
628 #endif //FEATURE_ASYNC_IO
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) {
660 internal sealed class SyncTextWriter
: TextWriter
, IDisposable
662 private TextWriter _out
;
664 internal SyncTextWriter(TextWriter t
): base(t
.FormatProvider
) {
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
689 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
690 protected override void Dispose(bool disposing
) {
691 // Explicitly pick up a potentially methodimpl'ed Dispose
693 ((IDisposable
)_out
).Dispose();
696 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
697 public override void Flush() {
701 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
702 public override void Write(char value) {
706 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
707 public override void Write(char[] 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) {
722 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
723 public override void Write(int value) {
727 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
728 public override void Write(uint value) {
732 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
733 public override void Write(long value) {
737 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
738 public override void Write(ulong value) {
742 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
743 public override void Write(float value) {
747 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
748 public override void Write(double value) {
752 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
753 public override void Write(Decimal
value) {
757 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
758 public override void Write(String
value) {
762 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
763 public override void Write(Object
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() {
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
);
880 // On SyncTextWriter all APIs should run synchronously, even the async ones.
883 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
885 public override Task
WriteAsync(char value)
888 return Task
.CompletedTask
;
891 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
893 public override Task
WriteAsync(String
value)
896 return Task
.CompletedTask
;
899 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
901 public override Task
WriteAsync(char[] buffer
, int index
, int count
)
903 Write(buffer
, index
, count
);
904 return Task
.CompletedTask
;
907 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
909 public override Task
WriteLineAsync(char value)
912 return Task
.CompletedTask
;
915 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
917 public override Task
WriteLineAsync(String
value)
920 return Task
.CompletedTask
;
923 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
925 public override Task
WriteLineAsync(char[] buffer
, int index
, int count
)
927 WriteLine(buffer
, index
, count
);
928 return Task
.CompletedTask
;
931 [MethodImplAttribute(MethodImplOptions
.Synchronized
)]
933 public override Task
FlushAsync()
936 return Task
.CompletedTask
;
938 #endif //FEATURE_ASYNC_IO