Author: zoltan
Date: 2007-09-11 14:15:08 -0400 (Tue, 11 Sep 2007)
New Revision: 85650

Modified:
   trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
   trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs
Log:
2007-09-11  Zoltan Varga  <[EMAIL PROTECTED]>

        * MethodBuilderTest.cs: Add new tests for using generic types in the IL
        code stream.


Modified: trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog        
2007-09-11 18:07:27 UTC (rev 85649)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog        
2007-09-11 18:15:08 UTC (rev 85650)
@@ -1,3 +1,8 @@
+2007-09-11  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * MethodBuilderTest.cs: Add new tests for using generic types in the IL
+       code stream.
+
 2007-09-09  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * MethodBuilderTest.cs: Add a new test.

Modified: 
trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs     
2007-09-11 18:07:27 UTC (rev 85649)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs     
2007-09-11 18:15:08 UTC (rev 85650)
@@ -858,8 +858,12 @@
                        Assert.IsTrue (attr.ThrowOnUnmappableChar, "#3");
                }
 
+               public class GenericFoo <T> {
+                       public static T field;
+               }
+
                [Test]
-               public void GenericTypeParameterBuilder_Dynamic ()
+               public void ILGen_GenericTypeParameterBuilder ()
                {
                        TypeBuilder tb = module.DefineType (genTypeName (), 
TypeAttributes.Public);
                        MethodBuilder mb = tb.DefineMethod ("box_int", 
@@ -877,6 +881,53 @@
                        MethodInfo mi2 = mi.MakeGenericMethod (new Type [] { 
typeof (int) });
                        Assert.AreEqual (1, mi2.Invoke (null, new object [] { 1 
}));
                }
+
+               public void ILGen_InstantiatedGenericType ()
+               {
+                       TypeBuilder tb = module.DefineType (genTypeName (), 
TypeAttributes.Public);
+                       MethodBuilder mb = tb.DefineMethod ("return_type", 
+                                                                               
                MethodAttributes.Public|MethodAttributes.Static, typeof 
(object), new Type [] { });
+
+                       GenericTypeParameterBuilder[] pars = 
mb.DefineGenericParameters (new string [] { "foo" });
+
+                       ILGenerator ilgen = mb.GetILGenerator ();
+
+                       Type genericFoo = typeof 
(GenericFoo<int>).GetGenericTypeDefinition ().MakeGenericType (new Type [] { 
pars [0] });
+
+                       ilgen.Emit (OpCodes.Ldtoken, genericFoo);
+                       ilgen.Emit (OpCodes.Call, typeof (Type).GetMethod 
("GetTypeFromHandle"));
+                       ilgen.Emit (OpCodes.Ret);
+
+                       Type t = tb.CreateType ();
+                       MethodInfo mi = t.GetMethod ("box_int");
+                       MethodInfo mi2 = mi.MakeGenericMethod (new Type [] { 
typeof (int) });
+                       Assert.AreEqual (typeof (GenericFoo<int>), mi2.Invoke 
(null, new object [] { 1 }));
+               }
+
+               public void ILGen_InstantiatedTypeBuilder ()
+               {
+                       TypeBuilder genericTb = module.DefineType (genTypeName 
(), TypeAttributes.Public);
+                       genericTb.DefineGenericParameters (new string [] { 
"foo" });
+                       Type generatedGenericType = genericTb.CreateType ();
+
+                       TypeBuilder tb = module.DefineType (genTypeName (), 
TypeAttributes.Public);
+                       MethodBuilder mb = tb.DefineMethod ("return_type", 
+                                                                               
                MethodAttributes.Public|MethodAttributes.Static, typeof 
(object), new Type [] { });
+
+                       GenericTypeParameterBuilder[] pars = 
mb.DefineGenericParameters (new string [] { "foo" });
+
+                       ILGenerator ilgen = mb.GetILGenerator ();
+
+                       ilgen.Emit (OpCodes.Ldtoken, genericTb.MakeGenericType 
(new Type [] { pars [0] }));
+                       ilgen.Emit (OpCodes.Call, typeof (Type).GetMethod 
("GetTypeFromHandle"));
+                       ilgen.Emit (OpCodes.Ret);
+
+                       Type t = tb.CreateType ();
+                       MethodInfo mi = t.GetMethod ("return_type");
+                       MethodInfo mi2 = mi.MakeGenericMethod (new Type [] { 
typeof (int) });
+                       Assert.AreEqual (generatedGenericType.MakeGenericType 
(new Type [] { typeof (int) }), mi2.Invoke (null, new object [] { 1 }));
+               }
+
 #endif
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to