2010-05-11 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / generic_type_definition.2.cs
blobdf1d5e8fdbf51888e7334e58d9fe4dcb9e0dc4fb
1 using System;
2 using System.Threading;
3 using System.Reflection;
4 using System.Reflection.Emit;
6 namespace TestApp
8 public class A<T> {
9 public T fld;
12 class Program
14 static AssemblyBuilder assembly;
15 static ModuleBuilder module;
16 static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
18 static void SetUp ()
20 AssemblyName assemblyName = new AssemblyName ();
21 assemblyName.Name = ASSEMBLY_NAME;
23 assembly =
24 Thread.GetDomain ().DefineDynamicAssembly (
25 assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, ".");
27 module = assembly.DefineDynamicModule ("module1", "Module1.dll");
30 static int Main()
32 Type gtd = typeof (A<>);
33 Type oi = gtd.MakeGenericType (gtd.GetGenericArguments ());
35 if (oi != gtd) {
36 Console.WriteLine ("fully open instantiation of static type not the same of the generic type definition");
37 return 1;
40 SetUp ();
41 TypeBuilder tb = module.DefineType ("Nullable`1", TypeAttributes.Public);
42 Type[] args = tb.DefineGenericParameters ("T");
43 Type type = tb.MakeGenericType (args);
45 if (type == tb) {
46 Console.WriteLine ("fully open instantiation of TypeBuilder is the same of the TypeBuilder");
47 return 2;
50 Type res = tb.CreateType ();
51 Type oires = res.MakeGenericType (res.GetGenericArguments ());
53 if (res != oires) {
54 Console.WriteLine ("fully open instantiation not the same of the generic type definition for the TypeBuilder created type");
55 return 3;
58 try {
59 type.GetConstructors ();
60 } catch (Exception e) {
61 Console.WriteLine ("fully open instantiation of TypeBuilder must have GetConstructors working {0}", e);
62 return 4;
66 try {
67 oires.GetConstructors ();
68 } catch (Exception e) {
69 Console.WriteLine ("fully open instantiation of the TypeBuilder created type must have GetConstructors working {0}", e);
70 return 5;
73 return 0;