Class Conversion
Provides task result conversion methods.
Inherited Members
Namespace: DotNext.Threading.Tasks
Assembly: DotNext.dll
Syntax
public static class Conversion
Methods
| Edit this page View SourceAsDynamic(Task)
Allows to convert Task<TResult> of unknown result type into dynamically
typed task which result can be obtained as object
or any other data type using dynamic
approach.
Declaration
public static DynamicTaskAwaitable AsDynamic(this Task task)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The arbitrary task of type Task<TResult>. |
Returns
Type | Description |
---|---|
DynamicTaskAwaitable | The dynamically typed task. |
Remarks
The type of the returned task is not known at compile time and therefore treated as dynamic
. The result value returned
by await
operator is equal to Value if task
is not of type Task<TResult>.
Convert<TInput, TOutput>(Task<TInput>)
Converts one type of task into another.
Declaration
public static Task<TOutput> Convert<TInput, TOutput>(this Task<TInput> task) where TInput : TOutput
Parameters
Type | Name | Description |
---|---|---|
Task<TInput> | task | The task to convert. |
Returns
Type | Description |
---|---|
Task<TOutput> | The converted task. |
Type Parameters
Name | Description |
---|---|
TInput | The source task type. |
TOutput | The target task type. |
Convert<TInput, TOutput>(Task<TInput>, Converter<TInput, Task<TOutput>>)
Converts one type of task into another.
Declaration
public static Task<TOutput> Convert<TInput, TOutput>(this Task<TInput> task, Converter<TInput, Task<TOutput>> converter)
Parameters
Type | Name | Description |
---|---|---|
Task<TInput> | task | The task to convert. |
Converter<TInput, Task<TOutput>> | converter | Asynchronous conversion function. |
Returns
Type | Description |
---|---|
Task<TOutput> | The converted task. |
Type Parameters
Name | Description |
---|---|
TInput | The source task type. |
TOutput | The target task type. |
Convert<TInput, TOutput>(Task<TInput>, Converter<TInput, TOutput>)
Converts one type of task into another.
Declaration
public static Task<TOutput> Convert<TInput, TOutput>(this Task<TInput> task, Converter<TInput, TOutput> converter)
Parameters
Type | Name | Description |
---|---|---|
Task<TInput> | task | The task to convert. |
Converter<TInput, TOutput> | converter | Non-blocking conversion function. |
Returns
Type | Description |
---|---|
Task<TOutput> | The converted task. |
Type Parameters
Name | Description |
---|---|
TInput | The source task type. |
TOutput | The target task type. |
SuspendException(Task, Predicate<Exception>?)
Suspends the exception that can be raised by the task.
Declaration
public static SuspendedExceptionTaskAwaitable SuspendException(this Task task, Predicate<Exception>? filter = null)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The task. |
Predicate<Exception> | filter | The filter of the exception to be suspended. |
Returns
Type | Description |
---|---|
SuspendedExceptionTaskAwaitable | The awaitable object that suspends exceptions according to the filter. |
SuspendException(ValueTask, Predicate<Exception>?)
Suspends the exception that can be raised by the task.
Declaration
public static SuspendedExceptionTaskAwaitable SuspendException(this ValueTask task, Predicate<Exception>? filter = null)
Parameters
Type | Name | Description |
---|---|---|
ValueTask | task | The task. |
Predicate<Exception> | filter | The filter of the exception to be suspended. |
Returns
Type | Description |
---|---|
SuspendedExceptionTaskAwaitable | The awaitable object that suspends exceptions according to the filter. |
SuspendException<TArg>(Task, TArg, Func<Exception, TArg, bool>)
Suspends the exception that can be raised by the task.
Declaration
public static SuspendedExceptionTaskAwaitable<TArg> SuspendException<TArg>(this Task task, TArg arg, Func<Exception, TArg, bool> filter)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The task. |
TArg | arg | The argument to be passed to the filter. |
Func<Exception, TArg, bool> | filter | The filter of the exception to be suspended. |
Returns
Type | Description |
---|---|
SuspendedExceptionTaskAwaitable<TArg> | The awaitable object that suspends exceptions according to the filter. |
Type Parameters
Name | Description |
---|---|
TArg |
SuspendException<TArg>(ValueTask, TArg, Func<Exception, TArg, bool>)
Suspends the exception that can be raised by the task.
Declaration
public static SuspendedExceptionTaskAwaitable<TArg> SuspendException<TArg>(this ValueTask task, TArg arg, Func<Exception, TArg, bool> filter)
Parameters
Type | Name | Description |
---|---|---|
ValueTask | task | The task. |
TArg | arg | The argument to be passed to the filter. |
Func<Exception, TArg, bool> | filter | The filter of the exception to be suspended. |
Returns
Type | Description |
---|---|
SuspendedExceptionTaskAwaitable<TArg> | The awaitable object that suspends exceptions according to the filter. |
Type Parameters
Name | Description |
---|---|
TArg |
ToNullable<T>(Task<T>)
Converts value type into nullable value type.
Declaration
public static Task<T?> ToNullable<T>(this Task<T> task) where T : struct
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | The task to convert. |
Returns
Type | Description |
---|---|
Task<T?> | The converted task. |
Type Parameters
Name | Description |
---|---|
T | The value type. |