Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-anon-172.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c316a1ba24004592447e13a5ad4ac4b5bd46bf30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
	}
}