2 using System
.Reflection
.Emit
;
3 using System
.Reflection
;
7 public static int Main ()
9 var dynMethod
= new DynamicMethod ("Metoda", MethodAttributes
.Public
| MethodAttributes
.Static
, CallingConventions
.Standard
,
10 null, Type
.EmptyTypes
, typeof (MainClass
), true);
11 var generator
= dynMethod
.GetILGenerator ();
13 generator
.Emit (OpCodes
.Ldc_I4_7
);
14 GenerateCodeCall (generator
, (int a
) => {
15 Console
.WriteLine (a
);
18 generator
.Emit (OpCodes
.Ret
);
20 var deleg
= (Action
)dynMethod
.CreateDelegate (typeof (Action
));
25 static void GenerateCodeCall
<T1
> (ILGenerator generator
, Action
<T1
> a
)
27 generator
.Emit (OpCodes
.Call
, a
.Method
);