1+ using System . Diagnostics ;
12using System . Diagnostics . CodeAnalysis ;
3+ using System . Reflection ;
24using static InlineIL . IL ;
35using static InlineIL . IL . Emit ;
46using static InlineIL . MethodRef ;
@@ -20,11 +22,16 @@ private static class Cache<T>
2022
2123 static Cache ( )
2224 {
23- Ldnull ( ) ;
24- Ldftn ( PropertyGet ( Type < Task < T > > ( ) , nameof ( Task < T > . Result ) ) ) ;
25- Newobj ( Constructor ( Type < Func < Task < T > , T > > ( ) , Type < object > ( ) , Type < IntPtr > ( ) ) ) ;
26- Pop ( out Func < Task < T > , T > propertyGetter ) ;
27- ResultGetter = propertyGetter ;
25+ Ldtoken ( PropertyGet ( Type < Task < T > > ( ) , nameof ( Task < T > . Result ) ) ) ;
26+ Pop ( out RuntimeMethodHandle getterHandle ) ;
27+
28+ Ldtoken < Task < T > > ( ) ;
29+ Pop ( out RuntimeTypeHandle taskHandle ) ;
30+
31+ var getterInfo = MethodBase . GetMethodFromHandle ( getterHandle , taskHandle ) as MethodInfo ;
32+ Debug . Assert ( getterInfo is not null ) ;
33+
34+ ResultGetter = getterInfo . CreateDelegate < Func < Task < T > , T > > ( ) ;
2835 }
2936 }
3037
@@ -34,11 +41,16 @@ static TaskType()
3441 {
3542 CompletedTaskType = Task . CompletedTask . GetType ( ) ;
3643
37- Ldnull ( ) ;
38- Ldftn ( PropertyGet ( Type < Task > ( ) , nameof ( Task . IsCompletedSuccessfully ) ) ) ;
39- Newobj ( Constructor ( Type < Func < Task , bool > > ( ) , Type < object > ( ) , Type < IntPtr > ( ) ) ) ;
40- Pop ( out Func < Task , bool > propertyGetter ) ;
41- IsCompletedSuccessfullyGetter = propertyGetter ;
44+ Ldtoken ( PropertyGet ( Type < Task > ( ) , nameof ( Task . IsCompletedSuccessfully ) ) ) ;
45+ Pop ( out RuntimeMethodHandle getterHandle ) ;
46+
47+ Ldtoken < Task > ( ) ;
48+ Pop ( out RuntimeTypeHandle taskHandle ) ;
49+
50+ var getterInfo = MethodBase . GetMethodFromHandle ( getterHandle , taskHandle ) as MethodInfo ;
51+ Debug . Assert ( getterInfo is not null ) ;
52+
53+ IsCompletedSuccessfullyGetter = getterInfo . CreateDelegate < Func < Task , bool > > ( ) ;
4254 }
4355
4456 /// <summary>
0 commit comments