[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / dynamic-method-access.2.cs
blob0be531c782001c9135d3266a533ec689f8ba8dfd
1 using System;
2 using System.Reflection;
3 using System.Reflection.Emit;
5 class Host {
7 static int Field = 42;
10 class Program {
12 delegate int Getter ();
14 public static int Main ()
16 DynamicMethod method = new DynamicMethod ("GetField",
17 typeof (int), new Type [0], Type.GetType ("Host"));
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);
25 Getter g = (Getter) method.CreateDelegate (typeof (Getter));
27 Console.WriteLine (g ());
28 if (g () == 42)
29 return 0;
30 return 1;