Class DataTransferObject
Various extension methods for IDataTransferObject.
Inherited Members
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public static class DataTransferObject
Methods
| Improve this Doc View SourceGetObjectDataAsync<TResult, TObject>(TObject, Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>>, CancellationToken)
Converts data transfer object to another type.
Declaration
public static ValueTask<TResult> GetObjectDataAsync<TResult, TObject>(this TObject dto, Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>> parser, CancellationToken token = default(CancellationToken))
where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to decode. |
Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>> | parser | 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. |
GetObjectDataAsync<TResult, TObject>(TObject, CancellationToken)
Gets the data encapsulated by the data transfer object.
Declaration
public static ValueTask<TResult> GetObjectDataAsync<TResult, TObject>(this TObject dto, CancellationToken token = default(CancellationToken))
where TResult : IDataTransferObject.IDecoder<TResult>, new()
where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask<TResult> | The data extracted from DTO. |
Type Parameters
Name | Description |
---|---|
TResult | The type representing another form of data transfer object. |
TObject | The type of the data transfer object. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ToByteArrayAsync<TObject>(TObject, CancellationToken)
Converts DTO to array of bytes.
Declaration
public static Task<byte[]> ToByteArrayAsync<TObject>(this TObject dto, CancellationToken token = default(CancellationToken))
where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
Task<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, Int32, CancellationToken)
Converts DTO content to string.
Declaration
public static Task<string> ToStringAsync<TObject>(this TObject dto, Encoding encoding, int capacity, CancellationToken token = default(CancellationToken))
where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
Encoding | encoding | The encoding used to decode stored string. |
Int32 | capacity | The maximum possible size of the message, in bytes. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
Task<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. |
ToStringAsync<TObject>(TObject, Encoding, CancellationToken)
Converts DTO content to string.
Declaration
public static Task<string> ToStringAsync<TObject>(this TObject dto, Encoding encoding, CancellationToken token = default(CancellationToken))
where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
Encoding | encoding | The encoding used to decode stored string. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
Task<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. |
ToType<TResult, TObject>(TObject, CancellationToken)
Converts DTO to value of blittable type.
Declaration
public static ValueTask<TResult> ToType<TResult, TObject>(this TObject dto, CancellationToken token = default(CancellationToken))
where TResult : struct where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Data transfer object to read from. |
CancellationToken | token | The token that can be used to cancel asynchronous operation. |
Returns
Type | Description |
---|---|
ValueTask<TResult> | The content of the object. |
Type Parameters
Name | Description |
---|---|
TResult | The type of result. |
TObject | The type of 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(CancellationToken))
where TObject : 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, CancellationToken)
Copies the object content to the specified pipe writer.
Declaration
public static ValueTask WriteToAsync<TObject>(this TObject dto, PipeWriter output, CancellationToken token = default(CancellationToken))
where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Transfer data object to transform. |
PipeWriter | output | The pipe writer receiving object content. |
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, Int32, 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(CancellationToken))
where TObject : IDataTransferObject
Parameters
Type | Name | Description |
---|---|---|
TObject | dto | Transfer data object to transform. |
Stream | output | The output stream receiving object content. |
Int32 | 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(CancellationToken))
where TObject : 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. |