diff --git a/src/Sandbox/Program.cs b/src/Sandbox/Program.cs index 4170304..983d614 100644 --- a/src/Sandbox/Program.cs +++ b/src/Sandbox/Program.cs @@ -8,6 +8,58 @@ namespace Pose.Sandbox { + namespace System.Runtime.CompilerServices + { + // AsyncVoidMethodBuilder.cs in your project + public class AsyncTaskMethodBuilder + { + 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 SetStateMachine(IAsyncStateMachine stateMachine) {} + + public void SetException(Exception exception) {} + + public Task Task => null; + + public AsyncTaskMethodBuilder() + => Console.WriteLine(".ctor"); + + public static AsyncTaskMethodBuilder Create() + => new AsyncTaskMethodBuilder(); + + public void SetResult() => Console.WriteLine("SetResult"); + + public void Start(ref TStateMachine stateMachine) + where TStateMachine : IAsyncStateMachine + { + Console.WriteLine("Start"); + var methodInfos = stateMachine.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); + var methodRewriter = MethodRewriter.CreateRewriter(methodInfos[0], false); + var methodBase = methodRewriter.Rewrite(); + stateMachine.MoveNext(); + } + + // AwaitOnCompleted, AwaitUnsafeOnCompleted, SetException + // and SetStateMachine are empty + } + } + public class Program { public static async Task GetAsyncInt() => await Task.FromResult(1); @@ -20,18 +72,18 @@ public static async Task Lol() public static void Main(string[] args) { - //Lol().GetAwaiter().GetResult(); - - var shim = Shim - .Replace(() => Program.GetAsyncInt()) - .With(() => Task.FromResult(2)); + Lol().GetAwaiter().GetResult(); - PoseContext.IsolateAsync( - async () => - { - var @int = await GetAsyncInt(); - Console.WriteLine(@int); - }, shim).GetAwaiter().GetResult(); + // var shim = Shim + // .Replace(() => Program.GetAsyncInt()) + // .With(() => Task.FromResult(2)); + // + // PoseContext.IsolateAsync( + // async () => + // { + // var @int = await GetAsyncInt(); + // Console.WriteLine(@int); + // }, shim).GetAwaiter().GetResult(); /* #if NET48 Console.WriteLine("4.8");