| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016 |
- // 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.Globalization;
- using System.Threading.Tasks;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Buffers;
- using System.Diagnostics.CodeAnalysis;
- 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.
- public abstract partial class TextWriter : MarshalByRefObject, IDisposable, IAsyncDisposable
- {
- public static readonly TextWriter Null = new NullTextWriter();
- // We don't want to allocate on every TextWriter creation, so cache the char array.
- private static readonly char[] s_coreNewLine = Environment.NewLineConst.ToCharArray();
- /// <summary>
- /// This is the 'NewLine' property expressed as a char[].
- /// It is exposed to subclasses as a protected field for read-only
- /// purposes. You should only modify it by using the 'NewLine' property.
- /// In particular you should never modify the elements of the array
- /// as they are shared among many instances of TextWriter.
- /// </summary>
- protected char[] CoreNewLine = s_coreNewLine;
- private string CoreNewLineStr = Environment.NewLineConst;
- // Can be null - if so, ask for the Thread's CurrentCulture every time.
- private readonly 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 CultureInfo.CurrentCulture;
- }
- else
- {
- return _internalFormatProvider;
- }
- }
- }
- public virtual void Close()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- public virtual ValueTask DisposeAsync()
- {
- try
- {
- Dispose();
- return default;
- }
- catch (Exception exc)
- {
- return new ValueTask(Task.FromException(exc));
- }
- }
- // 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;
- }
- /// <summary>
- /// Returns the line terminator string used by this TextWriter. The default line
- /// terminator string is Environment.NewLine, which is platform specific.
- /// On Windows this is a carriage return followed by a line feed ("\r\n").
- /// On OSX and Linux this is a line feed ("\n").
- /// </summary>
- /// <remarks>
- /// 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".
- /// </remarks>
- [AllowNull]
- public virtual string NewLine
- {
- get => CoreNewLineStr;
- set
- {
- if (value == null)
- {
- value = Environment.NewLineConst;
- }
- CoreNewLineStr = value;
- CoreNewLine = value.ToCharArray();
- }
- }
- // 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), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
- for (int i = 0; i < count; i++) Write(buffer[index + i]);
- }
- // Writes a span of characters to the text stream.
- //
- public virtual void Write(ReadOnlySpan<char> buffer)
- {
- char[] array = ArrayPool<char>.Shared.Rent(buffer.Length);
- try
- {
- buffer.CopyTo(new Span<char>(array));
- Write(array, 0, buffer.Length);
- }
- finally
- {
- ArrayPool<char>.Shared.Return(array);
- }
- }
- // Writes the text representation of a boolean to the text stream. This
- // method outputs either bool.TrueString or bool.FalseString.
- //
- public virtual void Write(bool value)
- {
- Write(value ? "True" : "False");
- }
- // Writes the text representation of an integer to the text stream. The
- // text representation of the given value is produced by calling the
- // int.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
- // uint.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
- // long.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 ulong.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)
- {
- if (value is IFormattable f)
- {
- Write(f.ToString(null, FormatProvider));
- }
- else
- Write(value.ToString());
- }
- }
- /// <summary>
- /// Equivalent to Write(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
- public virtual void Write(StringBuilder? value)
- {
- if (value != null)
- {
- foreach (ReadOnlyMemory<char> chunk in value.GetChunks())
- Write(chunk.Span);
- }
- }
- // 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 Environment.NewLine, 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();
- }
- public virtual void WriteLine(ReadOnlySpan<char> buffer)
- {
- char[] array = ArrayPool<char>.Shared.Rent(buffer.Length);
- try
- {
- buffer.CopyTo(new Span<char>(array));
- WriteLine(array, 0, buffer.Length);
- }
- finally
- {
- ArrayPool<char>.Shared.Return(array);
- }
- }
- // 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)
- {
- Write(value);
- }
- Write(CoreNewLineStr);
- }
- /// <summary>
- /// Equivalent to WriteLine(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- public virtual void WriteLine(StringBuilder? value)
- {
- Write(value);
- 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.
- if (value is IFormattable f)
- {
- 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
- 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);
- }
- 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);
- }
- /// <summary>
- /// Equivalent to WriteAsync(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
- public virtual Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- return
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- value == null ? Task.CompletedTask :
- WriteAsyncCore(value, cancellationToken);
- async Task WriteAsyncCore(StringBuilder sb, CancellationToken ct)
- {
- foreach (ReadOnlyMemory<char> chunk in sb.GetChunks())
- {
- await WriteAsync(chunk, ct).ConfigureAwait(false);
- }
- }
- }
- public Task WriteAsync(char[]? buffer)
- {
- if (buffer == null)
- {
- return Task.CompletedTask;
- }
- return WriteAsync(buffer, 0, buffer.Length);
- }
- 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);
- }
- public virtual Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default) =>
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- MemoryMarshal.TryGetArray(buffer, out ArraySegment<char> array) ?
- WriteAsync(array.Array!, array.Offset, array.Count) :
- Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, ReadOnlyMemory<char>>)state!;
- t.Item1.Write(t.Item2.Span);
- }, Tuple.Create(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- 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);
- }
- 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);
- }
- /// <summary>
- /// Equivalent to WriteLineAsync(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
- public virtual Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- return
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- value == null ? WriteAsync(CoreNewLine, cancellationToken) :
- WriteLineAsyncCore(value, cancellationToken);
- async Task WriteLineAsyncCore(StringBuilder sb, CancellationToken ct)
- {
- foreach (ReadOnlyMemory<char> chunk in sb.GetChunks())
- {
- await WriteAsync(chunk, ct).ConfigureAwait(false);
- }
- await WriteAsync(CoreNewLine, ct).ConfigureAwait(false);
- }
- }
- public Task WriteLineAsync(char[]? buffer)
- {
- if (buffer == null)
- {
- return WriteLineAsync();
- }
- return WriteLineAsync(buffer, 0, buffer.Length);
- }
- 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);
- }
- public virtual Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default) =>
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- MemoryMarshal.TryGetArray(buffer, out ArraySegment<char> array) ?
- WriteLineAsync(array.Array!, array.Offset, array.Count) :
- Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, ReadOnlyMemory<char>>)state!;
- t.Item1.WriteLine(t.Item2.Span);
- }, Tuple.Create(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- public virtual Task WriteLineAsync()
- {
- return WriteAsync(CoreNewLine);
- }
- public virtual Task FlushAsync()
- {
- return Task.Factory.StartNew(state => ((TextWriter)state!).Flush(), this,
- CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
- #endregion
- private sealed class NullTextWriter : TextWriter
- {
- internal NullTextWriter() : base(CultureInfo.InvariantCulture)
- {
- }
- public override Encoding Encoding => Encoding.Unicode;
- 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)
- {
- }
- public override void Write(char value)
- {
- }
- }
- public static TextWriter Synchronized(TextWriter writer)
- {
- if (writer == null)
- throw new ArgumentNullException(nameof(writer));
- return writer is SyncTextWriter ? writer : new SyncTextWriter(writer);
- }
- internal sealed class SyncTextWriter : TextWriter, IDisposable
- {
- private readonly TextWriter _out;
- internal SyncTextWriter(TextWriter t) : base(t.FormatProvider)
- {
- _out = t;
- }
- public override Encoding Encoding => _out.Encoding;
- public override IFormatProvider FormatProvider => _out.FormatProvider;
- [AllowNull]
- public override string NewLine
- {
- [MethodImpl(MethodImplOptions.Synchronized)]
- get => _out.NewLine;
- [MethodImpl(MethodImplOptions.Synchronized)]
- set => _out.NewLine = value;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Close() => _out.Close();
- [MethodImpl(MethodImplOptions.Synchronized)]
- protected override void Dispose(bool disposing)
- {
- // Explicitly pick up a potentially methodimpl'ed Dispose
- if (disposing)
- ((IDisposable)_out).Dispose();
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Flush() => _out.Flush();
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(char value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(char[]? buffer) => _out.Write(buffer);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(char[] buffer, int index, int count) => _out.Write(buffer, index, count);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(ReadOnlySpan<char> buffer) => _out.Write(buffer);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(bool value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(int value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(uint value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(long value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(ulong value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(float value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(double value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(decimal value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string? value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(StringBuilder? value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(object? value) => _out.Write(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object? arg0) => _out.Write(format, arg0);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object? arg0, object? arg1) => _out.Write(format, arg0, arg1);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object? arg0, object? arg1, object? arg2) => _out.Write(format, arg0, arg1, arg2);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object?[] arg) => _out.Write(format, arg);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine() => _out.WriteLine();
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(char value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(decimal value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(char[]? buffer) => _out.WriteLine(buffer);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(char[] buffer, int index, int count) => _out.WriteLine(buffer, index, count);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(ReadOnlySpan<char> buffer) => _out.WriteLine(buffer);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(bool value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(int value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(uint value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(long value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(ulong value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(float value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(double value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string? value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(StringBuilder? value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(object? value) => _out.WriteLine(value);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string format, object? arg0) => _out.WriteLine(format, arg0);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string format, object? arg0, object? arg1) => _out.WriteLine(format, arg0, arg1);
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string format, object? arg0, object? arg1, object? arg2) => _out.WriteLine(format, arg0, arg1, arg2);
- [MethodImpl(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.
- //
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override ValueTask DisposeAsync()
- {
- Dispose();
- return default;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(char value)
- {
- Write(value);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(string? value)
- {
- Write(value);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
- Write(value);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(char[] buffer, int index, int count)
- {
- Write(buffer, index, count);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
- Write(buffer.Span);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
- WriteLine(buffer.Span);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(char value)
- {
- WriteLine(value);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync()
- {
- WriteLine();
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(string? value)
- {
- WriteLine(value);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
- WriteLine(value);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(char[] buffer, int index, int count)
- {
- WriteLine(buffer, index, count);
- return Task.CompletedTask;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task FlushAsync()
- {
- Flush();
- return Task.CompletedTask;
- }
- }
- }
- }
|