Conversion
Provides task result conversion methods.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace DotNext.Threading.Tasks
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public static class Conversion
{
public static Task<TOutput> Convert<[System.Runtime.CompilerServices.Nullable(0)] TInput, [System.Runtime.CompilerServices.Nullable(2)] TOutput>(this Task<TInput> task) where TInput : TOutput
{
return task.Convert(Converter.Identity<TInput, TOutput>());
}
[AsyncStateMachine(typeof(<Convert>d__1<, >))]
public static Task<TOutput> Convert<[System.Runtime.CompilerServices.Nullable(2)] TInput, [System.Runtime.CompilerServices.Nullable(2)] TOutput>(this Task<TInput> task, Converter<TInput, TOutput> converter)
{
<Convert>d__1<TInput, TOutput> stateMachine = default(<Convert>d__1<TInput, TOutput>);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<TOutput>.Create();
stateMachine.task = task;
stateMachine.converter = converter;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[System.Runtime.CompilerServices.NullableContext(0)]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public static Task<T?> ToNullable<T>([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})] this Task<T> task) where T : struct
{
return task.Convert((Converter<T, T?>)((T value) => value));
}
[AsyncStateMachine(typeof(<Convert>d__3<, >))]
public static Task<TOutput> Convert<[System.Runtime.CompilerServices.Nullable(2)] TInput, [System.Runtime.CompilerServices.Nullable(2)] TOutput>(this Task<TInput> task, Converter<TInput, Task<TOutput>> converter)
{
<Convert>d__3<TInput, TOutput> stateMachine = default(<Convert>d__3<TInput, TOutput>);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<TOutput>.Create();
stateMachine.task = task;
stateMachine.converter = converter;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[RequiresUnreferencedCode("Runtime binding may be incompatible with IL trimming")]
public static DynamicTaskAwaitable AsDynamic(this Task task)
{
return new DynamicTaskAwaitable(task, true);
}
}
}