Merge pull request #5210 from alexrp/profiler-runtime-settings
[mono.git] / mono / tests / dynamic-method-access.2.cs
1 using System;
2 using System.Reflection;
3 using System.Reflection.Emit;
4
5 class Host {
6
7         static int Field = 42;
8 }
9
10 class Program {
11
12         delegate int Getter ();
13
14         public static int Main ()
15         {
16                 DynamicMethod method = new DynamicMethod ("GetField",
17                         typeof (int), new Type [0], Type.GetType ("Host"));
18
19                 ILGenerator il = method.GetILGenerator ();
20                 il.Emit (OpCodes.Ldsfld, typeof (Host).GetField (
21                         "Field", BindingFlags.Static |
22 BindingFlags.NonPublic));
23                 il.Emit (OpCodes.Ret);
24
25                 Getter g = (Getter) method.CreateDelegate (typeof (Getter));
26
27                 Console.WriteLine (g ());
28                 if (g () == 42)
29                         return 0;
30                 return 1;
31         }
32 }