Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / codegen-interfaces.cs
1 using System;
2 using System.Reflection;
3 using System.Reflection.Emit;
4
5 class CGen {
6
7         public static int Main() {
8                 AssemblyBuilder abuilder;
9                 ModuleBuilder mbuilder;
10                 TypeBuilder tbuilder;
11                 FieldBuilder fbuilder;
12                 PropertyBuilder pbuilder;
13                 AssemblyName an;
14                 String name = "tcgen.exe";
15                 MethodBuilder method, get_method;
16                 TypeAttributes attrs = TypeAttributes.Public | TypeAttributes.Class;
17                 MethodAttributes mattrs = MethodAttributes.Public | MethodAttributes.Static;
18                 byte[] body = {0x16, 0x2a}; // ldc.i4.0 ret
19
20                 an = new AssemblyName ();
21                 an.Name = name;
22                 abuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Save);
23
24                 mbuilder = abuilder.DefineDynamicModule (name, name);
25
26                 tbuilder = mbuilder.DefineType ("Test.CodeGen", attrs, null, new Type [0]);
27                 Type result = typeof(int);
28                 Type[] param = new Type[] {typeof (String[])};
29                 method = tbuilder.DefineMethod("Main", mattrs, result, param);
30                 method.CreateMethodBody (body, body.Length);
31
32                 fbuilder = tbuilder.DefineField ("int_field", typeof(int), FieldAttributes.Private);
33                 fbuilder = tbuilder.DefineField ("string_field", typeof(string), FieldAttributes.Public);
34                 /*pbuilder = tbuilder.DefineProperty ("FieldI", PropertyAttributes.None, typeof(int), null);
35                 get_method = tbuilder.DefineMethod("get_FieldI", MethodAttributes.Public, result, null);
36                 get_method.CreateMethodBody (body, body.Length);
37                 pbuilder.SetGetMethod (get_method);*/
38
39                 Type t = tbuilder.CreateType ();
40                 abuilder.SetEntryPoint (method);
41                 abuilder.Save (name);
42                 return 0;
43         }
44 }