using System; using System.Threading.Tasks; using System.Runtime.CompilerServices; [AsyncMethodBuilder (typeof(MyTaskMethodBuilder<>))] class MyTask { } [AsyncMethodBuilder (typeof(MyTaskMethodBuilder))] class MyTask { } class MyTaskMethodBuilder { public static MyTaskMethodBuilder Create() { return null; } public MyTask Task { get { return null; } } public void SetException (Exception exception) { } public void SetResult () { } public void AwaitOnCompleted (ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { } public void AwaitUnsafeOnCompleted (ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { } public void Start (ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { } public void SetStateMachine (IAsyncStateMachine stateMachine) { } } class MyTaskMethodBuilder { public static MyTaskMethodBuilder Create() { return null; } public MyTask Task { get { return null; } } public void SetException (Exception exception) { } public void SetResult (T result) { } public void AwaitOnCompleted (ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { } public void AwaitUnsafeOnCompleted (ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { } public void Start (ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { } public void SetStateMachine (IAsyncStateMachine stateMachine) { } } class X { public async MyTask Test () { await Task.Delay (1); } public async MyTask Test2 () { await Task.Delay (1); return 2; } public async ValueTask Test3 () { await Task.Delay (1); return "as"; } public static void Main () { var x = new X (); var r1 = x.Test3 ().Result; } }