181b81b4a4
Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
31 lines
727 B
C#
31 lines
727 B
C#
using System;
|
|
using System.Reflection.Emit;
|
|
using System.Reflection;
|
|
|
|
class MainClass
|
|
{
|
|
public static int Main ()
|
|
{
|
|
var dynMethod = new DynamicMethod ("Metoda", MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard,
|
|
null, Type.EmptyTypes, typeof (MainClass), true);
|
|
var generator = dynMethod.GetILGenerator ();
|
|
|
|
generator.Emit (OpCodes.Ldc_I4_7);
|
|
GenerateCodeCall (generator, (int a) => {
|
|
Console.WriteLine (a);
|
|
});
|
|
|
|
generator.Emit (OpCodes.Ret);
|
|
|
|
var deleg = (Action)dynMethod.CreateDelegate (typeof (Action));
|
|
deleg ();
|
|
return 0;
|
|
}
|
|
|
|
static void GenerateCodeCall<T1> (ILGenerator generator, Action<T1> a)
|
|
{
|
|
generator.Emit (OpCodes.Call, a.Method);
|
|
}
|
|
}
|
|
|