[Mono-bugs] [Bug 54945][Nor] New - GetCustomAttributes failing for fields defined in a base class
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Fri, 27 Feb 2004 13:03:22 -0500 (EST)
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 lluis@ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=54945
--- shadow/54945 2004-02-27 13:03:21.000000000 -0500
+++ shadow/54945.tmp.10224 2004-02-27 13:03:21.000000000 -0500
@@ -0,0 +1,55 @@
+Bug#: 54945
+Product: Mono/Class Libraries
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: lluis@ximian.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: GetCustomAttributes failing for fields defined in a base class
+
+GetCustomAttributes is not returning the correct result for fields defined
+in a base class, but only if they are got using Type.GetFields.
+
+This is a test case. Notice that the first Console.WriteLine prints the
+correct value, but when getting the field with GetFields, it does not.
+
+using System;
+using System.Reflection;
+
+class Test
+{
+ public static void Main ()
+ {
+ int i = typeof(Derived).GetField ("field").GetCustomAttributes
+(typeof(MyAttribute), true).Length;
+ Console.WriteLine ("field attributes: " + i);
+
+ FieldInfo[] fieldInfos = typeof(Derived).GetFields ();
+ foreach (FieldInfo f in fieldInfos)
+ Console.WriteLine ("{0} {1}", f.Name, f.GetCustomAttributes
+(typeof(MyAttribute), true).Length);
+ }
+}
+
+public class Base
+{
+ [My]
+ public string field;
+}
+
+public class Derived: Base
+{
+}
+
+public class MyAttribute: Attribute
+{
+}