[System] Use GZipStream from corefx
[mono-project.git] / mono / tests / dynamic-generic-size.cs
blob3a26f728d1055765d177f51ae0d943cebf48e784
1 using System;
2 using System.Threading;
3 using System.Reflection;
4 using System.Reflection.Emit;
5 using System.Collections.Generic;
7 namespace GenericSize
9 class GenericSize
11 static int Iterations = 10000;
12 static AssemblyBuilder assembly;
13 static ModuleBuilder module;
14 static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
16 static void SetUp ()
18 AssemblyName assemblyName = new AssemblyName ();
19 assemblyName.Name = ASSEMBLY_NAME;
21 assembly =
22 Thread.GetDomain ().DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.Run);
24 module = assembly.DefineDynamicModule ("module1");
27 static int Main()
29 SetUp ();
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));
42 il.Emit(OpCodes.Ret);
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));
54 if (i % 15 == 0)
55 GC.Collect();
58 return 0;