Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs (C#)

Code before:
                t.Item1.WriteLine(t.Item2, t.Item3, t.Item4);
            }, new TupleSlim<TextWriter, char[], int, int>(this, buffer, index, count), 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(static state =>
                {
                    var t = (TupleSlim<TextWriter, ReadOnlyMemory<char>>)state!;
                    t.Item1.WriteLine(t.Item2.Span);
                }, new TupleSlim<TextWriter, ReadOnlyMemory<char>>(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);

        public virtual Task WriteLineAsync()
        {
            return WriteAsync(CoreNewLine);
        }

        public Task WriteLineAsync(CancellationToken cancellationToken) =>
            WriteAsync(CoreNewLine, cancellationToken);

        public virtual Task FlushAsync()
        {
            return Task.Factory.StartNew(static state => ((TextWriter)state!).Flush(), this,
                CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        /// <summary>
        /// Asynchronously clears all buffers for the current writer and causes any buffered data to
        /// be written to the underlying device.
        /// </summary>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests.</param>
        /// <returns>A <see cref="Task"/> that represents the asynchronous flush operation.</returns>
        /// <exception cref="ObjectDisposedException">The text writer is disposed.</exception>
        /// <exception cref="InvalidOperationException">The writer is currently in use by a previous write operation.</exception>
        public virtual Task FlushAsync(CancellationToken cancellationToken) =>
            cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
            FlushAsync();
        #endregion

        private sealed class NullTextWriter : TextWriter
        {
            internal NullTextWriter() { }

            public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture;
            public override Encoding Encoding => Encoding.Unicode;
            [AllowNull]
            public override string NewLine { get => base.NewLine; set { } }

            // To avoid all unnecessary overhead in the base, override all Flush/Write methods as pure nops.


Review comment (suggestion):
Missing XML documentation. According to the documentation guidelines in `.github/prompts/docs.prompt.md`, public methods should be documented with XML comments.

Add documentation following this pattern:
```csharp
/// <summary>
/// Writes a line terminator to the text stream asynchronously.
/// </summary>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A task that represents the asynchronous write operation.</returns>
public Task WriteLineAsync(CancellationToken cancellationToken) =>
```
```suggestion

        /// <summary>
        /// Writes a line terminator to the text stream asynchronously.
        /// </summary>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
```

Code after:

            return WriteLineAsync(buffer, 0, buffer.Length);
        }

        public virtual Task WriteLineAsync(char[] buffer, int index, int count) =>
            Task.Factory.StartNew(static state =>
            {
                var t = (TupleSlim<TextWriter, char[], int, int>)state!;
                t.Item1.WriteLine(t.Item2, t.Item3, t.Item4);
            }, new TupleSlim<TextWriter, char[], int, int>(this, buffer, index, count), 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(static state =>
                {
                    var t = (TupleSlim<TextWriter, ReadOnlyMemory<char>>)state!;
                    t.Item1.WriteLine(t.Item2.Span);
                }, new TupleSlim<TextWriter, ReadOnlyMemory<char>>(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);

        public virtual Task WriteLineAsync()
        {
            return WriteAsync(CoreNewLine);
        }

        /// <summary>
        /// Writes a line terminator to the text stream asynchronously.
        /// </summary>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
        public Task WriteLineAsync(CancellationToken cancellationToken) =>
            WriteAsync(CoreNewLine, cancellationToken);

        public virtual Task FlushAsync()
        {
            return Task.Factory.StartNew(static state => ((TextWriter)state!).Flush(), this,
                CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        }

        /// <summary>
        /// Asynchronously clears all buffers for the current writer and causes any buffered data to
        /// be written to the underlying device.
        /// </summary>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests.</param>
        /// <returns>A <see cref="Task"/> that represents the asynchronous flush operation.</returns>
        /// <exception cref="ObjectDisposedException">The text writer is disposed.</exception>
        /// <exception cref="InvalidOperationException">The writer is currently in use by a previous write operation.</exception>
        public virtual Task FlushAsync(CancellationToken cancellationToken) =>
            cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
            FlushAsync();