2 using System
.Threading
;
3 using System
.Reflection
;
4 using System
.Reflection
.Emit
;
7 using System
.Security
.Permissions
;
8 using System
.Runtime
.InteropServices
;
9 using System
.Collections
.Generic
;
12 public static Gen
<T
>[] newSelfArr () {
18 public static void Test () {
19 Gen
<int>.newSelfArr ();
23 public class GenericsTests
25 static AssemblyBuilder assembly
;
26 static ModuleBuilder module
;
30 AssemblyName assemblyName
= new AssemblyName ();
31 assemblyName
.Name
= "TestAssembly";
33 Thread
.GetDomain ().DefineDynamicAssembly (
34 assemblyName
, AssemblyBuilderAccess
.RunAndSave
, ".");
35 module
= assembly
.DefineDynamicModule ("module1", "TestModuleSS.dll");
38 public static int Main () {
40 TypeBuilder tb
= module
.DefineType ("Gen", TypeAttributes
.Public
);
41 Type
[] args
= tb
.DefineGenericParameters ("T");
42 Type oi
= tb
.MakeGenericType (args
);
44 MethodBuilder mb
= tb
.DefineMethod ("Test", MethodAttributes
.Public
| MethodAttributes
.Static
, oi
.MakeArrayType (), new Type
[0]);
46 ILGenerator il
= mb
.GetILGenerator();
47 il
.Emit (OpCodes
.Ldnull
);
48 il
.Emit (OpCodes
.Ret
);
51 TypeBuilder main
= module
.DefineType ("Driver", TypeAttributes
.Public
);
52 MethodBuilder mb2
= main
.DefineMethod ("Test", MethodAttributes
.Public
| MethodAttributes
.Static
);
54 il
= mb2
.GetILGenerator();
55 il
.Emit (OpCodes
.Call
, TypeBuilder
.GetMethod (tb
.MakeGenericType (typeof (int)), mb
));
56 il
.Emit (OpCodes
.Pop
);
57 il
.Emit (OpCodes
.Ret
);
58 Type tt
= main
.CreateType ();
60 tt
.GetMethod ("Test").Invoke (null, null);
61 //typeof (Driver).GetMethod ("Test").Invoke (null, null);