Show / Hide Table of Contents

Class TextStreamExtensions

Represents various extension methods for TextWriter and TextReader classes.

Inheritance
object
TextStreamExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public static class TextStreamExtensions

Methods

View Source

Create(ReadOnlySequence<byte>, Encoding, int, MemoryAllocator<char>?)

Creates TextReader over the sequence of encoded characters.

Declaration
public static TextReader Create(ReadOnlySequence<byte> sequence, Encoding encoding, int bufferSize = 1024, MemoryAllocator<char>? allocator = null)
Parameters
Type Name Description
ReadOnlySequence<byte> sequence

The sequence of bytes representing encoded characters.

Encoding encoding

The encoding of the characters in the sequence.

int bufferSize

The size of the internal char buffer used to decode characters.

MemoryAllocator<char> allocator

The allocator of the internal buffer.

Returns
Type Description
TextReader

The reader over the sequence of encoded characters.

Exceptions
Type Condition
ArgumentNullException

encoding is null; or bufferSize is less than or equal to zero.

View Source

Create(ReadOnlySequence<char>)

Creates TextReader over the sequence of characters.

Declaration
public static TextReader Create(ReadOnlySequence<char> sequence)
Parameters
Type Name Description
ReadOnlySequence<char> sequence

The sequence of characters.

Returns
Type Description
TextReader

The reader over the sequence of characters.

View Source

Create<TWriter>(TWriter, IFormatProvider?, Action<TWriter>?, Func<TWriter, CancellationToken, Task>?)

Creates text writer backed by the char buffer writer.

Declaration
public static TextWriter Create<TWriter>(TWriter writer, IFormatProvider? provider = null, Action<TWriter>? flush = null, Func<TWriter, CancellationToken, Task>? flushAsync = null) where TWriter : class, IBufferWriter<char>
Parameters
Type Name Description
TWriter writer

The buffer writer.

IFormatProvider provider

The object that controls formatting.

Action<TWriter> flush

The optional implementation of Flush() method.

Func<TWriter, CancellationToken, Task> flushAsync

The optional implementation of FlushAsync(CancellationToken) method.

Returns
Type Description
TextWriter

The text writer backed by the buffer writer.

Type Parameters
Name Description
TWriter

The type of the char buffer writer.

View Source

Create<TWriter>(TWriter, Encoding, IFormatProvider?, Action<TWriter>?, Func<TWriter, CancellationToken, Task>?)

Creates text writer backed by the byte buffer writer.

Declaration
public static TextWriter Create<TWriter>(TWriter writer, Encoding encoding, IFormatProvider? provider = null, Action<TWriter>? flush = null, Func<TWriter, CancellationToken, Task>? flushAsync = null) where TWriter : class, IBufferWriter<byte>
Parameters
Type Name Description
TWriter writer

The buffer writer.

Encoding encoding

The encoding used to converts chars to bytes.

IFormatProvider provider

The object that controls formatting.

Action<TWriter> flush

The optional implementation of Flush() method.

Func<TWriter, CancellationToken, Task> flushAsync

The optional implementation of FlushAsync(CancellationToken) method.

Returns
Type Description
TextWriter

The text writer backed by the buffer writer.

Type Parameters
Name Description
TWriter

The type of the char buffer writer.

Exceptions
Type Condition
ArgumentNullException

encoding is null.

View Source

ReadAllAsync(TextReader, int, MemoryAllocator<char>?, CancellationToken)

Reads text stream sequentially.

Declaration
public static IAsyncEnumerable<ReadOnlyMemory<char>> ReadAllAsync(this TextReader receiver, int bufferSize, MemoryAllocator<char>? allocator = null, CancellationToken token = default)
Parameters
Type Name Description
TextReader receiver
int bufferSize

The buffer size.

MemoryAllocator<char> allocator

The allocator of the buffer.

CancellationToken token

The token that can be used to cancel the enumeration.

Returns
Type Description
IAsyncEnumerable<ReadOnlyMemory<char>>

A collection of memory blocks that can be obtained sequentially to read a whole stream.

Remarks

The returned memory block should not be used between iterations.

Exceptions
Type Condition
ArgumentOutOfRangeException

bufferSize is less than 1.

View Source

Write(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler)

Writes interpolated string and appends a new line after it.

Declaration
public static void Write(this TextWriter receiver, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

View Source

Write(TextWriter, MemoryAllocator<char>?, IFormatProvider?, ref PoolingInterpolatedStringHandler)

Writes interpolated string and appends a new line after it.

Declaration
public static void Write(this TextWriter receiver, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

IFormatProvider provider

Optional formatting provider to be applied for each interpolated string argument.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

View Source

WriteAsync(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler, CancellationToken)

Writes interpolated string.

Declaration
public static ValueTask WriteAsync(this TextWriter receiver, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

A task that represents the asynchronous write operation.

View Source

WriteAsync(TextWriter, MemoryAllocator<char>?, IFormatProvider?, ref PoolingInterpolatedStringHandler, CancellationToken)

Writes interpolated string.

Declaration
public static ValueTask WriteAsync(this TextWriter receiver, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

IFormatProvider provider

Optional formatting provider to be applied for each interpolated string argument.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

A task that represents the asynchronous write operation.

View Source

WriteAsync(TextWriter, ReadOnlySequence<char>, CancellationToken)

Asynchronously writes a linked regions of characters to the text stream.

Declaration
public static ValueTask WriteAsync(this TextWriter receiver, ReadOnlySequence<char> chars, CancellationToken token = default)
Parameters
Type Name Description
TextWriter receiver
ReadOnlySequence<char> chars

The linked regions of characters.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous execution of this method.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

View Source

WriteLine(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler)

Writes interpolated string and appends a new line after it.

Declaration
public static void WriteLine(this TextWriter receiver, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

View Source

WriteLine(TextWriter, MemoryAllocator<char>?, IFormatProvider?, ref PoolingInterpolatedStringHandler)

Writes interpolated string and appends a new line after it.

Declaration
public static void WriteLine(this TextWriter receiver, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

IFormatProvider provider

Optional formatting provider to be applied for each interpolated string argument.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

View Source

WriteLineAsync(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler, CancellationToken)

Writes interpolated string and appends a new line after it.

Declaration
public static ValueTask WriteLineAsync(this TextWriter receiver, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

A task that represents the asynchronous write operation.

View Source

WriteLineAsync(TextWriter, MemoryAllocator<char>?, IFormatProvider?, ref PoolingInterpolatedStringHandler, CancellationToken)

Writes interpolated string and appends a new line after it.

Declaration
public static ValueTask WriteLineAsync(this TextWriter receiver, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
Type Name Description
TextWriter receiver
MemoryAllocator<char> allocator

The allocator for the buffer used by string interpolation handler.

IFormatProvider provider

Optional formatting provider to be applied for each interpolated string argument.

PoolingInterpolatedStringHandler handler

The interpolated string handler.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

A task that represents the asynchronous write operation.

  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾