[Mono-bugs] [Bug 77002][Wis] Changed - TypeForwardToAttribute support

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Mar 14 19:20:36 EST 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by vargaz at gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=77002

--- shadow/77002	2005-12-16 07:50:45.000000000 -0500
+++ shadow/77002.tmp.8650	2006-03-14 19:20:36.000000000 -0500
@@ -70,6 +70,75 @@
 
 I think, actually, that this can/should be handled completely in the
 library: SRE.AssemblyBuilder.SetCustomAttribute, or SRE.ModuleBuilder.
 
 Ankit, you may want to look at the second link above and try to see
 what metadata tables are needed to implement this feature.
+
+------- Additional Comments From vargaz at gmail.com  2006-03-14 19:20 -------
+I added support for this to the runtime. gmcs can use the new
+internal AssemblyBuilder.AddTypeForwarder () method to register type 
+forwarders.
+
+Here are the test cases I used:
+
+<<<<<<<<<<<<<< forward1.cs >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+public class Foo
+{
+}
+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+<<<<<<<<<<<<<<< test.cs >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Runtime.CompilerServices;
+
+public class Test {
+
+    public static void Main(string[] args) {
+		Assembly a = Assembly.LoadFrom ("forward1.dll");
+		Type forwardedType = a.GetType ("Foo");
+
+        AppDomain currentDomain = AppDomain.CurrentDomain;
+	AssemblyName asmName = new AssemblyName();
+	asmName.Name = "forward2";
+	string asmFileName = "forward2.dll";
+	AssemblyBuilder asmBuilder =
+	currentDomain.DefineDynamicAssembly(asmName, 
+	    AssemblyBuilderAccess.RunAndSave);
+        ModuleBuilder builder = 
+	    asmBuilder.DefineDynamicModule("_Created.netmodule", asmFileName);
+
+		typeof (AssemblyBuilder).GetMethod ("AddTypeForwarder",
+BindingFlags.NonPublic|BindingFlags.Instance).Invoke (asmBuilder, new
+Object [] { forwardedType });
+
+	asmBuilder.Save(asmFileName);
+    }
+}
+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+<<<<<<<<<<<<<<<<<<<<<< forward3.cs >>>>>>>>>>>>>>>>>>>>>>>>>
+
+using System;
+using System.Reflection;
+
+public class Tests {
+
+	public static void Main () {
+		Assembly a = Assembly.LoadFrom ("forward2.dll");
+		Console.WriteLine (a.GetType ("Foo"));
+		Console.WriteLine (a.GetType ("Foo").Assembly);
+	}
+}
+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+Usage:
+
+gmcs /target:library forward1.cs
+gmcs test.cs
+mono test.exe
+gmcs forward3.cs
+mono forward3.exe
+
+


More information about the mono-bugs mailing list