Class TextStreamExtensions
Represents various extension methods for TextWriter and TextReader classes.
Inherited Members
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public static class TextStreamExtensions
Methods
| Edit this page View SourceAsTextReader(ReadOnlySequence<byte>, Encoding, int, MemoryAllocator<char>?)
Creates TextReader over the sequence of encoded characters.
Declaration
public static TextReader AsTextReader(this 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 |
|
AsTextReader(ReadOnlySequence<char>)
Creates TextReader over the sequence of characters.
Declaration
public static TextReader AsTextReader(this 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. |
AsTextWriter<TWriter>(TWriter, IFormatProvider?, Action<TWriter>?, Func<TWriter, CancellationToken, Task>?)
Creates text writer backed by the char buffer writer.
Declaration
public static TextWriter AsTextWriter<TWriter>(this 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. |
AsTextWriter<TWriter>(TWriter, Encoding, IFormatProvider?, Action<TWriter>?, Func<TWriter, CancellationToken, Task>?)
Creates text writer backed by the byte buffer writer.
Declaration
public static TextWriter AsTextWriter<TWriter>(this 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 |
|
ReadAllAsync(TextReader, int, MemoryAllocator<char>?, CancellationToken)
Reads text stream sequentially.
Declaration
public static IAsyncEnumerable<ReadOnlyMemory<char>> ReadAllAsync(this TextReader reader, int bufferSize, MemoryAllocator<char>? allocator = null, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TextReader | reader | Readable stream. |
| 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 |
|
Write(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler)
Writes interpolated string and appends a new line after it.
Declaration
public static void Write(this TextWriter writer, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| MemoryAllocator<char> | allocator | The allocator for the buffer used by string interpolation handler. |
| PoolingInterpolatedStringHandler | handler | The interpolated string handler. |
Write(TextWriter, MemoryAllocator<char>?, IFormatProvider?, ref PoolingInterpolatedStringHandler)
Writes interpolated string and appends a new line after it.
Declaration
public static void Write(this TextWriter writer, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| 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. |
WriteAsync(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler, CancellationToken)
Writes interpolated string.
Declaration
public static ValueTask WriteAsync(this TextWriter writer, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| 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. |
WriteAsync(TextWriter, MemoryAllocator<char>?, IFormatProvider?, ref PoolingInterpolatedStringHandler, CancellationToken)
Writes interpolated string.
Declaration
public static ValueTask WriteAsync(this TextWriter writer, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| 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. |
WriteAsync(TextWriter, ReadOnlySequence<char>, CancellationToken)
Asynchronously writes a linked regions of characters to the text stream.
Declaration
public static ValueTask WriteAsync(this TextWriter writer, ReadOnlySequence<char> chars, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | The stream to write into. |
| 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. |
WriteLine(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler)
Writes interpolated string and appends a new line after it.
Declaration
public static void WriteLine(this TextWriter writer, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| MemoryAllocator<char> | allocator | The allocator for the buffer used by string interpolation handler. |
| PoolingInterpolatedStringHandler | handler | The interpolated string handler. |
WriteLine(TextWriter, MemoryAllocator<char>?, IFormatProvider?, ref PoolingInterpolatedStringHandler)
Writes interpolated string and appends a new line after it.
Declaration
public static void WriteLine(this TextWriter writer, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| 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. |
WriteLineAsync(TextWriter, MemoryAllocator<char>?, ref PoolingInterpolatedStringHandler, CancellationToken)
Writes interpolated string and appends a new line after it.
Declaration
public static ValueTask WriteLineAsync(this TextWriter writer, MemoryAllocator<char>? allocator, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| 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. |
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 writer, MemoryAllocator<char>? allocator, IFormatProvider? provider, ref PoolingInterpolatedStringHandler handler, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | An output for the interpolated string. |
| 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. |