[Mono-bugs] [Bug 75366][Maj] Changed - SRE uses Reflected not Declaring type for token

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Jul 1 04:56:40 EDT 2005


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 martin at ximian.com.

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

--- shadow/75366	2005-07-01 04:47:50.000000000 -0400
+++ shadow/75366.tmp.12414	2005-07-01 04:56:40.000000000 -0400
@@ -169,6 +169,44 @@
 ------- Additional Comments From martin at ximian.com  2005-07-01 04:47 -------
 The patch is a clear no-go - this code is there for a reason.
 
 It's not worth spending a week rewriting the whole generics code for
 this as there's an easy workaround (use Type.GetMembers() on the
 "correct" type, like mcs/gmcs does), so let's close this as WONTFIX.
+
+------- Additional Comments From martin at ximian.com  2005-07-01 04:56 -------
+Ben, to answer your question, in a `MonoReflectionField *f',
+`f->klass' is a generic type definition if the field is in a generic
+type and `f->field->parent' is a generic instance.
+
+So in
+
+====
+class Foo <T>
+{
+   public T foo;
+}
+
+class X
+{
+   static void Main ()
+   {
+     Foo<int> foo = new Foo<int>;
+     Console.WriteLine (foo.foo);
+  }
+}
+====
+
+these two become different - we have to encode the field as
+
+    ldfld !0 class [J]A`1<int32>::foo
+
+Unfortunately, the only way for GMCS to tell reflection to do that
+is doing something like
+
+    Type t = Type.GetType ("A`1<int>");
+    MemberInfo[] mi = t.GetMembers ("foo", MemberTypes.Field);
+    FieldInfo fi = (FieldInfo) mi [0];
+
+This returns a FieldInfo who's `DeclaringType` is the generic type
+definition `A<T>' and who's `ReflectedType' is the generic instance
+`A<int>'.


More information about the mono-bugs mailing list