[Mono-bugs] [Bug 24833] New - Attribute.GetCustomAttribute(MemberInfo, Type, bool) return null

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
16 May 2002 16:06:12 -0000


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 ndrochak@gol.com.

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

--- shadow/24833	Thu May 16 12:06:12 2002
+++ shadow/24833.tmp.19958	Thu May 16 12:06:12 2002
@@ -0,0 +1,77 @@
+Bug#: 24833
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: RedHat 7.2
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: ndrochak@gol.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Attribute.GetCustomAttribute(MemberInfo, Type, bool) return null
+
+Sample code shows the error.  A null should not be returned from 
+GetCustomAttribute().
+-----------------------------------------
+using System;
+
+namespace NS {
+	[AttributeUsage(AttributeTargets.Class, AllowMultiple=true, 
+Inherited=false)]
+	internal class MyCustomAttribute : Attribute {
+
+		private string _info;
+
+		public MyCustomAttribute (string info) {
+			_info = info;
+		}
+
+		public string Info {
+			get {
+				return _info;
+			}
+		}
+	}
+
+	[AttributeUsage(AttributeTargets.Class)]
+	internal class YourCustomAttribute : Attribute {
+		
+		private int _value;
+
+		public YourCustomAttribute (int value) {
+			_value = value;
+		}
+
+		public int Value {
+			get {
+				return _value;
+			}
+		}
+	}
+
+	[MyCustomAttribute("MyBaseClass"), YourCustomAttribute(37)]
+	internal class MyClass {
+		int Value { get { return 42; }}
+	}
+
+	[MyCustomAttribute("MyDerivedClass")]
+	internal class MyDerivedClass : MyClass {
+		public void Do () {}
+	}
+
+	class C {
+		public static int Main() {
+			if (null == Attribute.GetCustomAttribute(typeof
+(MyDerivedClass), typeof(YourCustomAttribute)))
+				return 1;
+			else
+				return 0;
+		}
+	}
+}