Show / Hide Table of Contents

Class Conversion

Provides task result conversion methods.

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

Methods

| Edit this page View Source

AsDynamic(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>.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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
| Edit this page View Source

SuspendException<T>(Task<T>)

Returns a task that never throws an exception.

Declaration
public static AwaitableResult<T> SuspendException<T>(this Task<T> task)
Parameters
Type Name Description
Task<T> task

The task to convert.

Returns
Type Description
AwaitableResult<T>

The task that never throws an exception. Instead, the Result<T> contains an exception.

Type Parameters
Name Description
T

The type of the task.

| Edit this page View Source

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
| Edit this page View Source

SuspendException<T>(ValueTask<T>)

Returns a task that never throws an exception.

Declaration
public static AwaitableResult<T> SuspendException<T>(this ValueTask<T> task)
Parameters
Type Name Description
ValueTask<T> task

The task to convert.

Returns
Type Description
AwaitableResult<T>

The task that never throws an exception. Instead, the Result<T> contains an exception.

Type Parameters
Name Description
T

The type of the task.

| Edit this page View Source

SuspendException<T, TError>(Task<T>, Converter<Exception, TError>)

Returns a task that never throws an exception.

Declaration
public static AwaitableResult<T, TError> SuspendException<T, TError>(this Task<T> task, Converter<Exception, TError> converter) where TError : struct, Enum
Parameters
Type Name Description
Task<T> task

The task to convert.

Converter<Exception, TError> converter

The exception converter.

Returns
Type Description
AwaitableResult<T, TError>

The task that never throws an exception. Instead, the Result<T> contains an exception.

Type Parameters
Name Description
T

The type of the task.

TError

The type of the error.

| Edit this page View Source

SuspendException<T, TError>(ValueTask<T>, Converter<Exception, TError>)

Returns a task that never throws an exception.

Declaration
public static AwaitableResult<T, TError> SuspendException<T, TError>(this ValueTask<T> task, Converter<Exception, TError> converter) where TError : struct, Enum
Parameters
Type Name Description
ValueTask<T> task

The task to convert.

Converter<Exception, TError> converter

The exception converter.

Returns
Type Description
AwaitableResult<T, TError>

The task that never throws an exception. Instead, the Result<T> contains an exception.

Type Parameters
Name Description
T

The type of the task.

TError

The type of the error.

| Edit this page View Source

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.

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