[Mono-bugs] [Bug 46185][Nor] New - Wrong implicit conversion of enum value when used in custom attribute

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Fri, 11 Jul 2003 18:33:21 -0400 (EDT)


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=46185

--- shadow/46185	Fri Jul 11 18:33:21 2003
+++ shadow/46185.tmp.4870	Fri Jul 11 18:33:21 2003
@@ -0,0 +1,70 @@
+Bug#: 46185
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: lluis@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Wrong implicit conversion of enum value when used in custom attribute
+
+Description of Problem:
+
+If a custom attribute has a constructor parameter or a property of type
+Object and it is applied to a class or whatever, using an enum value as
+value for the parameter or property, then that value is stored as int, not
+as an enum value.
+
+Hmm, this is difficult to explain :-). Just see the test case:
+
+using System;
+
+public enum Enu {a, b}
+
+[TestAttribute (Enu.a)]
+public class TestClass
+{
+	static void Main()
+	{
+		object[] ats = typeof(TestClass).GetCustomAttributes (false);
+		TestAttribute at = (TestAttribute) ats[0];
+		Console.WriteLine (at.Value.GetType());
+	}
+}
+
+class TestAttribute: Attribute
+{
+	public object Value;
+
+	public TestAttribute (object val)
+	{
+		Value = val;
+	}
+}
+
+
+Actual Results:
+System.Int32
+
+Expected Results:
+Enu
+
+How often does this happen? 
+Always
+
+Additional Information:
+If you do:
+
+object ob = Enu.a
+Console.WriteLine (ob.GetType())
+
+it returns the correct value, so it is something related to using the enum
+value as parameter of the custom attribute