Show / Hide Table of Contents

Class TextStreamExtensions

Represents various extension methods for TextWriter and TextReader classes.

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

Methods

| Edit this page View Source

AsTextReader(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

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

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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

encoding is null.

| Edit this page View Source

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

bufferSize is less than 1.

| Edit this page 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 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.

| Edit this page 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 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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page 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 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.

| Edit this page 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 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.

| Edit this page 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 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.

| Edit this page 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 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.

| Edit this page 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 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.

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