summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/IO/TextWriter.cs
blob: 131f69d35dbc3404e15f7e4fa719c810029dbbc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Threading.Tasks;

namespace System.IO {
    // This abstract base class represents a writer that can write a sequential
    // stream of characters. A subclass must minimally implement the 
    // Write(char) method.
    //
    // This class is intended for character output, not bytes.  
    // There are methods on the Stream class for writing bytes. 
    [Serializable]
    [ComVisible(true)]
    public abstract class TextWriter : MarshalByRefObject, IDisposable {
        public static readonly TextWriter Null = new NullTextWriter();

        // This should be initialized to Environment.NewLine, but
        // to avoid loading Environment unnecessarily so I've duplicated
        // the value here.
#if !PLATFORM_UNIX
        private const String InitialNewLine = "\r\n";

        protected char[] CoreNewLine = new char[] { '\r', '\n' };
#else
        private const String InitialNewLine = "\n";

        protected char[] CoreNewLine = new char[] {'\n'};
#endif // !PLATFORM_UNIX

        // Can be null - if so, ask for the Thread's CurrentCulture every time.
        private IFormatProvider InternalFormatProvider;

        protected TextWriter()
        {
            InternalFormatProvider = null;  // Ask for CurrentCulture all the time.
        }
    
        protected TextWriter(IFormatProvider formatProvider)
        {
            InternalFormatProvider = formatProvider;
        }

        public virtual IFormatProvider FormatProvider {
            get { 
                if (InternalFormatProvider == null)
                    return Thread.CurrentThread.CurrentCulture;
                else
                    return InternalFormatProvider;
            }
        }

        // Closes this TextWriter and releases any system resources associated with the
        // TextWriter. Following a call to Close, any operations on the TextWriter
        // may raise exceptions. This default method is empty, but descendant
        // classes can override the method to provide the appropriate
        // functionality.
        public virtual void Close() {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
        }


        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    
        // Clears all buffers for this TextWriter and causes any buffered data to be
        // written to the underlying device. This default method is empty, but
        // descendant classes can override the method to provide the appropriate
        // functionality.
        public virtual void Flush() {
        }

        public abstract Encoding Encoding {
            get;
        }

        // Returns the line terminator string used by this TextWriter. The default line
        // terminator string is a carriage return followed by a line feed ("\r\n").
        //
        // Sets the line terminator string for this TextWriter. The line terminator
        // string is written to the text stream whenever one of the
        // WriteLine methods are called. In order for text written by
        // the TextWriter to be readable by a TextReader, only one of the following line
        // terminator strings should be used: "\r", "\n", or "\r\n".
        // 
        public virtual String NewLine {
            get { return new String(CoreNewLine); }
            set {
                if (value == null) 
                    value = InitialNewLine;
                CoreNewLine = value.ToCharArray();
            }
        }
    

        public static TextWriter Synchronized(TextWriter writer) {
            if (writer==null)
                throw new ArgumentNullException(nameof(writer));
            Contract.Ensures(Contract.Result<TextWriter>() != null);
            Contract.EndContractBlock();

            if (writer is SyncTextWriter)
                return writer;
            
            return new SyncTextWriter(writer);
        }
        
        // Writes a character to the text stream. This default method is empty,
        // but descendant classes can override the method to provide the
        // appropriate functionality.
        //
        public virtual void Write(char value) {
        }
    
        // Writes a character array to the text stream. This default method calls
        // Write(char) for each of the characters in the character array.
        // If the character array is null, nothing is written.
        //
        public virtual void Write(char[] buffer) {
            if (buffer != null) Write(buffer, 0, buffer.Length);
        }
    
        // Writes a range of a character array to the text stream. This method will
        // write count characters of data into this TextWriter from the
        // buffer character array starting at position index.
        //
        public virtual void Write(char[] buffer, int index, int count) {
            if (buffer==null)
                throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer"));
            if (index < 0)
                throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            if (count < 0)
                throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            if (buffer.Length - index < count)
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
            Contract.EndContractBlock();

            for (int i = 0; i < count; i++) Write(buffer[index + i]);
        }
    
        // Writes the text representation of a boolean to the text stream. This
        // method outputs either Boolean.TrueString or Boolean.FalseString.
        //
        public virtual void Write(bool value) {
            Write(value ? Boolean.TrueLiteral : Boolean.FalseLiteral);
        }
    
        // Writes the text representation of an integer to the text stream. The
        // text representation of the given value is produced by calling the
        // Int32.ToString() method.
        //
        public virtual void Write(int value) {
            Write(value.ToString(FormatProvider));
        }
    
        // Writes the text representation of an integer to the text stream. The
        // text representation of the given value is produced by calling the
        // UInt32.ToString() method.
        //
        [CLSCompliant(false)]
        public virtual void Write(uint value) {
            Write(value.ToString(FormatProvider));
        }
    
        // Writes the text representation of a long to the text stream. The
        // text representation of the given value is produced by calling the
        // Int64.ToString() method.
        //
        public virtual void Write(long value) {
            Write(value.ToString(FormatProvider));
        }
    
        // Writes the text representation of an unsigned long to the text 
        // stream. The text representation of the given value is produced 
        // by calling the UInt64.ToString() method.
        //
        [CLSCompliant(false)]
        public virtual void Write(ulong value) {
            Write(value.ToString(FormatProvider));
        }
    
        // Writes the text representation of a float to the text stream. The
        // text representation of the given value is produced by calling the
        // Float.toString(float) method.
        //
        public virtual void Write(float value) {
            Write(value.ToString(FormatProvider));
        }
    
        // Writes the text representation of a double to the text stream. The
        // text representation of the given value is produced by calling the
        // Double.toString(double) method.
        //
        public virtual void Write(double value) {
            Write(value.ToString(FormatProvider));
        }
    
        public virtual void Write(Decimal value) {
            Write(value.ToString(FormatProvider));
        }
    
        // Writes a string to the text stream. If the given string is null, nothing
        // is written to the text stream.
        //
        public virtual void Write(String value) {
            if (value != null) Write(value.ToCharArray());
        }
    
        // Writes the text representation of an object to the text stream. If the
        // given object is null, nothing is written to the text stream.
        // Otherwise, the object's ToString method is called to produce the
        // string representation, and the resulting string is then written to the
        // output stream.
        //
        public virtual void Write(Object value) {
            if (value != null) {
                IFormattable f = value as IFormattable;
                if (f != null)
                    Write(f.ToString(null, FormatProvider));
                else
                    Write(value.ToString());
            }
        }
    
#if false
    //      // Converts the wchar * to a string and writes this to the stream.
    //      //
    //      __attribute NonCLSCompliantAttribute()
    //      public void Write(wchar *value) {
    //          Write(new String(value));
    //      }
    
    //      // Treats the byte* as a LPCSTR, converts it to a string, and writes it to the stream.
    //      // 
    //      __attribute NonCLSCompliantAttribute()
    //      public void Write(byte *value) {
    //          Write(new String(value));
    //      }
#endif
    
    
        // Writes out a formatted string.  Uses the same semantics as
        // String.Format.
        // 
        public virtual void Write(String format, Object arg0)
        {
            Write(String.Format(FormatProvider, format, arg0));
        }
        
        // Writes out a formatted string.  Uses the same semantics as
        // String.Format.
        // 
        public virtual void Write(String format, Object arg0, Object arg1)
        {
            Write(String.Format(FormatProvider, format, arg0, arg1));
        }
        
        // Writes out a formatted string.  Uses the same semantics as
        // String.Format.
        // 
        public virtual void Write(String format, Object arg0, Object arg1, Object arg2)
        {
            Write(String.Format(FormatProvider, format, arg0, arg1, arg2));
        }
        
        // Writes out a formatted string.  Uses the same semantics as
        // String.Format.
        // 
        public virtual void Write(String format, params Object[] arg)
        {
            Write(String.Format(FormatProvider, format, arg));
        }
        
    
        // Writes a line terminator to the text stream. The default line terminator
        // is a carriage return followed by a line feed ("\r\n"), but this value
        // can be changed by setting the NewLine property.
        //
        public virtual void WriteLine() {
            Write(CoreNewLine);
        }
    
        // Writes a character followed by a line terminator to the text stream.
        //
        public virtual void WriteLine(char value) {
            Write(value);
            WriteLine();
        }
    
        // Writes an array of characters followed by a line terminator to the text
        // stream.
        //
        public virtual void WriteLine(char[] buffer) {
            Write(buffer);
            WriteLine();
        }
    
        // Writes a range of a character array followed by a line terminator to the
        // text stream.
        //
        public virtual void WriteLine(char[] buffer, int index, int count) {
            Write(buffer, index, count);
            WriteLine();
        }
    
        // Writes the text representation of a boolean followed by a line
        // terminator to the text stream.
        //
        public virtual void WriteLine(bool value) {
            Write(value);
            WriteLine();
        }
    
        // Writes the text representation of an integer followed by a line
        // terminator to the text stream.
        //
        public virtual void WriteLine(int value) {
            Write(value);
            WriteLine();
        }
    
        // Writes the text representation of an unsigned integer followed by 
        // a line terminator to the text stream.
        //
        [CLSCompliant(false)]
        public virtual void WriteLine(uint value) {
            Write(value);
            WriteLine();
        }
    
        // Writes the text representation of a long followed by a line terminator
        // to the text stream.
        //
        public virtual void WriteLine(long value) {
            Write(value);
            WriteLine();
        }
    
        // Writes the text representation of an unsigned long followed by 
        // a line terminator to the text stream.
        //
        [CLSCompliant(false)]
        public virtual void WriteLine(ulong value) {
            Write(value);
            WriteLine();
        }
    
        // Writes the text representation of a float followed by a line terminator
        // to the text stream.
        //
        public virtual void WriteLine(float value) {
            Write(value);
            WriteLine();
        }
    
        // Writes the text representation of a double followed by a line terminator
        // to the text stream.
        //
        public virtual void WriteLine(double value) {
            Write(value);
            WriteLine();
        }

        public virtual void WriteLine(decimal value) {
            Write(value);
            WriteLine();
        }
    
        // Writes a string followed by a line terminator to the text stream.
        //
        public virtual void WriteLine(String value) {

            if (value==null) {
                WriteLine();
            }
            else {
                // We'd ideally like WriteLine to be atomic, in that one call
                // to WriteLine equals one call to the OS (ie, so writing to 
                // console while simultaneously calling printf will guarantee we
                // write out a string and new line chars, without any interference).
                // Additionally, we need to call ToCharArray on Strings anyways,
                // so allocating a char[] here isn't any worse than what we were
                // doing anyways.  We do reduce the number of calls to the 
                // backing store this way, potentially.
                int vLen = value.Length;
                int nlLen = CoreNewLine.Length;
                char[] chars = new char[vLen+nlLen];
                value.CopyTo(0, chars, 0, vLen);
                // CoreNewLine will almost always be 2 chars, and possibly 1.
                if (nlLen == 2) {
                    chars[vLen] = CoreNewLine[0];
                    chars[vLen+1] = CoreNewLine[1];
                }
                else if (nlLen == 1)
                    chars[vLen] = CoreNewLine[0];
                else
                    Buffer.InternalBlockCopy(CoreNewLine, 0, chars, vLen * 2, nlLen * 2);
                Write(chars, 0, vLen + nlLen);
            }
            /*
            Write(value);  // We could call Write(String) on StreamWriter...
            WriteLine();
            */
        }
    
        // Writes the text representation of an object followed by a line
        // terminator to the text stream.
        //
        public virtual void WriteLine(Object value) {
            if (value==null) {
                WriteLine();
            }
            else {
                // Call WriteLine(value.ToString), not Write(Object), WriteLine().
                // This makes calls to WriteLine(Object) atomic.
                IFormattable f = value as IFormattable;
                if (f != null)
                    WriteLine(f.ToString(null, FormatProvider));
                else
                    WriteLine(value.ToString());
            }
        }

        // Writes out a formatted string and a new line.  Uses the same 
        // semantics as String.Format.
        // 
        public virtual void WriteLine(String format, Object arg0)
        {
            WriteLine(String.Format(FormatProvider, format, arg0));
        }
        
        // Writes out a formatted string and a new line.  Uses the same 
        // semantics as String.Format.
        // 
        public virtual void WriteLine (String format, Object arg0, Object arg1)
        {
            WriteLine(String.Format(FormatProvider, format, arg0, arg1));
        }
        
        // Writes out a formatted string and a new line.  Uses the same 
        // semantics as String.Format.
        // 
        public virtual void WriteLine (String format, Object arg0, Object arg1, Object arg2)
        {
            WriteLine(String.Format(FormatProvider, format, arg0, arg1, arg2));
        }
        
        // Writes out a formatted string and a new line.  Uses the same 
        // semantics as String.Format.
        // 
        public virtual void WriteLine (String format, params Object[] arg)
        {
            WriteLine(String.Format(FormatProvider, format, arg));
        }

        #region Task based Async APIs
        [ComVisible(false)]
        public virtual Task WriteAsync(char value)
        {
            var tuple = new Tuple<TextWriter, char>(this, value);
            return Task.Factory.StartNew(state =>
            {
                var t = (Tuple<TextWriter, char>)state;
                t.Item1.Write(t.Item2);
            },
            tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        [ComVisible(false)]
        public virtual Task WriteAsync(String value)
        {
            var tuple = new Tuple<TextWriter, string>(this, value);
            return Task.Factory.StartNew(state =>
            {
                var t = (Tuple<TextWriter, string>)state;
                t.Item1.Write(t.Item2);
            },
            tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        [ComVisible(false)]
        public Task WriteAsync(char[] buffer)
        {
            if (buffer == null)  return Task.CompletedTask;
            return WriteAsync(buffer, 0, buffer.Length);
        }

        [ComVisible(false)]
        public virtual Task WriteAsync(char[] buffer, int index, int count)
        {
            var tuple = new Tuple<TextWriter, char[], int, int>(this, buffer, index, count);
            return Task.Factory.StartNew(state =>
            {
                var t = (Tuple<TextWriter, char[], int, int>)state;
                t.Item1.Write(t.Item2, t.Item3, t.Item4);
            },
            tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        [ComVisible(false)]
        public virtual Task WriteLineAsync(char value)
        {
            var tuple = new Tuple<TextWriter, char>(this, value);
            return Task.Factory.StartNew(state =>
            {
                var t = (Tuple<TextWriter, char>)state;
                t.Item1.WriteLine(t.Item2);
            },
            tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        [ComVisible(false)]
        public virtual Task WriteLineAsync(String value)
        {
            var tuple = new Tuple<TextWriter, string>(this, value);
            return Task.Factory.StartNew(state =>
            {
                var t = (Tuple<TextWriter, string>)state;
                t.Item1.WriteLine(t.Item2);
            },
            tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        [ComVisible(false)]
        public Task WriteLineAsync(char[] buffer)
        {
            if (buffer == null)  return Task.CompletedTask;
            return WriteLineAsync(buffer, 0, buffer.Length);
        }

        [ComVisible(false)]
        public virtual Task WriteLineAsync(char[] buffer, int index, int count)
        {
            var tuple = new Tuple<TextWriter, char[], int, int>(this, buffer, index, count);
            return Task.Factory.StartNew(state =>
            {
                var t = (Tuple<TextWriter, char[], int, int>)state;
                t.Item1.WriteLine(t.Item2, t.Item3, t.Item4);
            },
            tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        [ComVisible(false)]
        public virtual Task WriteLineAsync()
        {
            return WriteAsync(CoreNewLine);
        }

        [ComVisible(false)]
        public virtual Task FlushAsync()
        {
            return Task.Factory.StartNew(state =>
            {
                ((TextWriter)state).Flush();
            },
            this, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }
        #endregion

        [Serializable]
        private sealed class NullTextWriter : TextWriter
        {
            internal NullTextWriter(): base(CultureInfo.InvariantCulture) {
            }
        
            public override Encoding Encoding {
                get { return Encoding.Default;  }
            }

            [SuppressMessage("Microsoft.Contracts", "CC1055")]  // Skip extra error checking to avoid *potential* AppCompat problems.
            public override void Write(char[] buffer, int index, int count) {
            }
            
            public override void Write(String value) {
            }

            // Not strictly necessary, but for perf reasons
            public override void WriteLine() {
            }

            // Not strictly necessary, but for perf reasons
            public override void WriteLine(String value) {
            }
            
            public override void WriteLine(Object value) {
            }
        }
        
        [Serializable]
        internal sealed class SyncTextWriter : TextWriter, IDisposable
        {
            private TextWriter _out;
            
            internal SyncTextWriter(TextWriter t): base(t.FormatProvider) {
                _out = t;
            }

            public override Encoding Encoding {
                get { return _out.Encoding;  }
            }

            public override IFormatProvider FormatProvider {
                get { return _out.FormatProvider;  }
            }
            
            public override  String NewLine {
                [MethodImplAttribute(MethodImplOptions.Synchronized)]
                get { return _out.NewLine; }
                [MethodImplAttribute(MethodImplOptions.Synchronized)]
                set { _out.NewLine = value; }
            }
    
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Close() {
                // So that any overriden Close() gets run
                _out.Close();
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            protected override void Dispose(bool disposing) {
                // Explicitly pick up a potentially methodimpl'ed Dispose
                if (disposing)
                    ((IDisposable)_out).Dispose();
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Flush() {
                _out.Flush();
            }
    
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(char value) {
                _out.Write(value);
            }
    
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(char[] buffer) {
                _out.Write(buffer);
            }

            [SuppressMessage("Microsoft.Contracts", "CC1055")]  // Skip extra error checking to avoid *potential* AppCompat problems.
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(char[] buffer, int index, int count) {
                _out.Write(buffer, index, count);
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(bool value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(int value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(uint value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(long value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(ulong value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(float value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(double value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(Decimal value) {
                _out.Write(value);
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(String value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(Object value) {
                _out.Write(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(String format, Object arg0) {
                _out.Write(format, arg0);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(String format, Object arg0, Object arg1) {
                _out.Write(format, arg0, arg1);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(String format, Object arg0, Object arg1, Object arg2) {
                _out.Write(format, arg0, arg1, arg2);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void Write(String format, Object[] arg) {
                _out.Write(format, arg);
            }
    
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine() {
                _out.WriteLine();
            }
    
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(char value) {
                _out.WriteLine(value);
            }
    
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(decimal value) {
                _out.WriteLine(value);
            }
    
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(char[] buffer) {
                _out.WriteLine(buffer);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(char[] buffer, int index, int count) {
                _out.WriteLine(buffer, index, count);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(bool value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(int value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(uint value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(long value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(ulong value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(float value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(double value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(String value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(Object value) {
                _out.WriteLine(value);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(String format, Object arg0) {
                _out.WriteLine(format, arg0);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(String format, Object arg0, Object arg1) {
                _out.WriteLine(format, arg0, arg1);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(String format, Object arg0, Object arg1, Object arg2) {
                _out.WriteLine(format, arg0, arg1, arg2);
            }
            
            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            public override void WriteLine(String format, Object[] arg) {
                _out.WriteLine(format, arg);
            }


            //
            // On SyncTextWriter all APIs should run synchronously, even the async ones.
            //

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            [ComVisible(false)]
            public override Task WriteAsync(char value)
            {
                Write(value);
                return Task.CompletedTask;
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            [ComVisible(false)]
            public override Task WriteAsync(String value)
            {
                Write(value);
                return Task.CompletedTask;
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            [ComVisible(false)]
            public override Task WriteAsync(char[] buffer, int index, int count)
            {
                Write(buffer, index, count);
                return Task.CompletedTask;
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            [ComVisible(false)]
            public override Task WriteLineAsync(char value)
            {
                WriteLine(value);
                return Task.CompletedTask;
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            [ComVisible(false)]
            public override Task WriteLineAsync(String value)
            {
                WriteLine(value);
                return Task.CompletedTask;
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            [ComVisible(false)]
            public override Task WriteLineAsync(char[] buffer, int index, int count)
            {
                WriteLine(buffer, index, count);
                return Task.CompletedTask;
            }

            [MethodImplAttribute(MethodImplOptions.Synchronized)]
            [ComVisible(false)]
            public override Task FlushAsync()
            {
                Flush();
                return Task.CompletedTask;
            }
        }
    }
}