using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Security;
namespace Fort23.Core
{
///
/// Represents a builder for asynchronous methods that return a task.
///
public struct AsyncTaskMethodBuilder
{
private CTask _tcs;
// 1. Static Create method.
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static AsyncTaskMethodBuilder Create()
{
AsyncTaskMethodBuilder builder = new AsyncTaskMethodBuilder() {_tcs = CTask.Create()};
return builder;
}
// 2. TaskLike Task property.
[DebuggerHidden] public CTask Task => this._tcs;
// 3. SetException
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
public void SetException(Exception exception)
{
this._tcs.SetException(exception);
}
// 4. SetResult
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetResult()
{
this._tcs.SetResult();
}
// 5. AwaitOnCompleted
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
{
awaiter.OnCompleted(stateMachine.MoveNext);
}
// 6. AwaitUnsafeOnCompleted
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
[SecuritySafeCritical]
public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
{
awaiter.OnCompleted(stateMachine.MoveNext);
}
// 7. Start
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
{
stateMachine.MoveNext();
}
// 8. SetStateMachine
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetStateMachine(IAsyncStateMachine stateMachine)
{
}
}
///
/// Represents a builder for asynchronous methods that return a task.
///
///
public struct AsyncTaskMethodBuilder
{
private CTask _task;
// 1. Static Create method.
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static AsyncTaskMethodBuilder Create()
{
AsyncTaskMethodBuilder builder = new AsyncTaskMethodBuilder() {_task = CTask.Create()};
return builder;
}
// 2. TaskLike Task property.
[DebuggerHidden] public CTask Task => _task;
// 3. SetException
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetException(Exception exception)
{
_task.SetException(exception);
}
// 4. SetResult
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetResult(T ret)
{
_task.SetResult(ret);
}
// 5. AwaitOnCompleted
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
{
awaiter.OnCompleted(stateMachine.MoveNext);
}
// 6. AwaitUnsafeOnCompleted
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
[SecuritySafeCritical]
public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
{
awaiter.OnCompleted(stateMachine.MoveNext);
}
// 7. Start
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
{
stateMachine.MoveNext();
}
// 8. SetStateMachine
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
public void SetStateMachine(IAsyncStateMachine stateMachine)
{
}
}
}