Class DataTransferObject
Various extension methods for IDataTransferObject.
Inherited Members
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public static class DataTransferObject
Methods
| Edit this page View SourceToByteArrayAsync<TObject>(TObject, MemoryAllocator<byte>?, CancellationToken)
Converts DTO to an array of bytes.
Declaration
public static ValueTask<byte[]> ToByteArrayAsync<TObject>(this TObject dto, MemoryAllocator<byte>? allocator = null, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
MemoryAllocator<byte> | allocator | The memory allocator. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask<byte[]> | The content of the object. |
Type Parameters
Name | Description |
---|---|
TObject | The type of data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ToMemoryAsync<TObject>(TObject, MemoryAllocator<byte>?, CancellationToken)
Converts DTO to a block of memory.
Declaration
public static ValueTask<MemoryOwner<byte>> ToMemoryAsync<TObject>(this TObject dto, MemoryAllocator<byte>? allocator = null, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
MemoryAllocator<byte> | allocator | The memory allocator. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask<MemoryOwner<byte>> | The content of the object. |
Type Parameters
Name | Description |
---|---|
TObject | The type of data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ToStringAsync<TObject>(TObject, Encoding, MemoryAllocator<byte>?, CancellationToken)
Converts DTO content to string.
Declaration
public static ValueTask<string> ToStringAsync<TObject>(this TObject dto, Encoding encoding, MemoryAllocator<byte>? allocator = null, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
Encoding | encoding | The encoding used to decode stored string. |
MemoryAllocator<byte> | allocator | The memory allocator. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask<string> | The content of the object. |
Type Parameters
Name | Description |
---|---|
TObject | The type of data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
TransformAsync<TResult, TObject>(TObject, Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>>, CancellationToken)
Converts data transfer object to another type.
Declaration
public static ValueTask<TResult> TransformAsync<TResult, TObject>(this TObject dto, Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>> transformation, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to decode. |
Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>> | transformation | The parser instance. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask<TResult> | The converted DTO content. |
Type Parameters
Name | Description |
---|---|
TResult | The type of result. |
TObject | The type of the data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
WriteToAsync<TObject>(TObject, IBufferWriter<byte>, CancellationToken)
Copies the object content to the specified buffer.
Declaration
public static ValueTask WriteToAsync<TObject>(this TObject dto, IBufferWriter<byte> writer, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Transfer data object to transform. |
IBufferWriter<byte> | writer | The buffer writer. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing state of asynchronous execution. |
Type Parameters
Name | Description |
---|---|
TObject | The type of data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
WriteToAsync<TObject>(TObject, PipeWriter, long, CancellationToken)
Copies the object content to the specified pipe writer.
Declaration
public static ValueTask WriteToAsync<TObject>(this TObject dto, PipeWriter output, long bufferSize = 0, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Transfer data object to transform. |
PipeWriter | output | The pipe writer receiving object content. |
long | bufferSize | The maximum numbers of bytes that can be buffered in the memory without flushing. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing state of asynchronous execution. |
Type Parameters
Name | Description |
---|---|
TObject | The type of data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
WriteToAsync<TObject>(TObject, Stream, int, CancellationToken)
Copies the object content to the specified stream.
Declaration
public static ValueTask WriteToAsync<TObject>(this TObject dto, Stream output, int bufferSize = 1024, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Transfer data object to transform. |
Stream | output | The output stream receiving object content. |
int | bufferSize | The size of the buffer to be used for transformation. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing state of asynchronous execution. |
Type Parameters
Name | Description |
---|---|
TObject | The type of data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
WriteToAsync<TObject>(TObject, Stream, Memory<byte>, CancellationToken)
Copies the object content into the specified stream.
Declaration
public static ValueTask WriteToAsync<TObject>(this TObject dto, Stream output, Memory<byte> buffer, CancellationToken token = default) where TObject : notnull, IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Transfer data object to transform. |
Stream | output | The output stream receiving object content. |
Memory<byte> | buffer | The buffer to be used for transformation. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing state of asynchronous execution. |
Type Parameters
Name | Description |
---|---|
TObject | The type of data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |