Add assert when dllmap is disabled and fix support build in netcore mode
[mono-project.git] / mono / tests / generic_type_definition.2.cs
blobafd6792178c338075ae4aa547eb0de080b63fa83
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, ".");
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 oires.GetConstructors ();
60 } catch (Exception e) {
61 Console.WriteLine ("fully open instantiation of the TypeBuilder created type must have GetConstructors working {0}", e);
62 return 5;
65 return 0;