2 using System
.Threading
;
3 using System
.Reflection
;
4 using System
.Reflection
.Emit
;
5 using System
.Collections
.Generic
;
11 static int Iterations
= 10000;
12 static AssemblyBuilder assembly
;
13 static ModuleBuilder module
;
14 static string ASSEMBLY_NAME
= "MonoTests.System.Reflection.Emit.TypeBuilderTest";
18 AssemblyName assemblyName
= new AssemblyName ();
19 assemblyName
.Name
= ASSEMBLY_NAME
;
22 Thread
.GetDomain ().DefineDynamicAssembly (assemblyName
, AssemblyBuilderAccess
.Run
);
24 module
= assembly
.DefineDynamicModule ("module1");
31 TypeBuilder tb
= module
.DefineType ("Test", TypeAttributes
.Public
);
32 tb
.DefineGenericParameters ("T");
33 var tb_ctor
= tb
.DefineDefaultConstructor (MethodAttributes
.Public
);
35 var tb2
= module
.DefineType ("Test2", TypeAttributes
.Public
);
36 var g0
= tb2
.DefineGenericParameters ("T");
38 var mb
= tb2
.DefineMethod ("Foo", MethodAttributes
.Public
| MethodAttributes
.Static
, typeof (object), new Type
[0]);
40 var il
= mb
.GetILGenerator();
41 il
.Emit(OpCodes
.Newobj
, TypeBuilder
.GetConstructor (tb
.MakeGenericType (g0
), tb_ctor
));
44 var t1
= tb
.CreateType ();
45 var t2
= tb2
.CreateType ();
47 var ginst
= t2
.MakeGenericType (typeof (string));
48 var method
= ginst
.GetMethod ("Foo", BindingFlags
.Public
| BindingFlags
.Static
);
50 var lst
= new List
<Object
>();
52 for (int i
= 0; i
< GenericSize
.Iterations
; i
++) {
53 lst
.Add (method
.Invoke (null, null));