Merge pull request #1861 from saper/home-override
[mono-project.git] / mcs / tests / test-555.cs
blob2fa51da8e1be3e90c586d1077dd8b60dfb29a952
1 using System;
2 using System.Reflection;
3 using System.Reflection.Emit;
5 public class Test
7 public static int Main()
9 AssemblyName assemblyName = new AssemblyName ();
10 assemblyName.Name = "TestAssembly";
11 AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.Run);
13 ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule ("TestModule");
14 TypeBuilder typeBuilder = moduleBuilder.DefineType ("TestType", TypeAttributes.Public);
16 FieldBuilder fieldBuilder = typeBuilder.DefineField ("TestField",
17 typeof (int),
18 FieldAttributes.Private);
21 PropertyBuilder propertyBuilder = typeBuilder.DefineProperty ("TestProperty",
22 PropertyAttributes.HasDefault,
23 typeof (int),
24 new Type[] { typeof (int) });
26 MethodBuilder getMethodBuilder = typeBuilder.DefineMethod ("TestGetMethod",
27 MethodAttributes.Public,
28 typeof (int),
29 new Type[] { });
32 ILGenerator IL = getMethodBuilder.GetILGenerator();
34 IL.Emit (OpCodes.Ldarg_0);
35 IL.Emit (OpCodes.Ldfld, fieldBuilder);
36 IL.Emit (OpCodes.Ret);
39 MethodBuilder setMethodBuilder = typeBuilder.DefineMethod ("TestSetMethod",
40 MethodAttributes.Public,
41 null,
42 new Type[] { typeof(int) });
43 IL = setMethodBuilder.GetILGenerator();
45 IL.Emit (OpCodes.Ldarg_0);
46 IL.Emit (OpCodes.Ldarg_1);
47 IL.Emit (OpCodes.Stfld, fieldBuilder);
48 IL.Emit (OpCodes.Ret);
50 propertyBuilder.SetGetMethod (getMethodBuilder);
51 propertyBuilder.SetSetMethod (setMethodBuilder);
53 typeBuilder.CreateType ();
55 Type type = moduleBuilder.GetType ("TestType", true);
57 PropertyInfo propertyInfo = type.GetProperty ("TestProperty");
59 return 0;