[Mono-bugs] [Bug 79666][Nor] New - can't use arrays of enums as cattr parameters

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sun Oct 15 07:27:29 EDT 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=79666

--- shadow/79666	2006-10-15 07:27:29.000000000 -0400
+++ shadow/79666.tmp.19389	2006-10-15 07:27:29.000000000 -0400
@@ -0,0 +1,71 @@
+Bug#: 79666
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: vargaz at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: can't use arrays of enums as cattr parameters
+
+The testcase is an extended version of test-454.cs. csc compiles it fine,
+while mcs says:
+
+test-454.cs(23,33): error CS0182: An attribute argument must be a constant
+expression, typeof expression or array creation expression
+
+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+// Test various kinds of arrays as custom attribute parameters
+using System;
+
+enum EnumType {
+	X,
+	Y
+};
+
+class FooAttribute : Attribute
+{
+	public string [] StringValues;
+	public object [] ObjectValues;
+	public EnumType [] EnumValues;
+	public Type [] Types;
+
+	public FooAttribute ()
+	{
+	}
+}
+
+[Foo (StringValues = new string [] {"foo", "bar", "baz"},
+	ObjectValues = new object [] {1, 'A', "B"},
+	EnumValues = new EnumType [] { EnumType.X, EnumType.Y },
+	Types = new Type [] {typeof (int), typeof (Type)}
+	)]
+class Test
+{
+	public static void Main () 
+	{
+		FooAttribute foo = (FooAttribute) typeof (Test)
+			.GetCustomAttributes (false) [0];
+		if (foo.StringValues [0] != "foo"
+			|| foo.StringValues [1] != "bar"
+			|| foo.StringValues [2] != "baz"
+			|| 1 != (int) foo.ObjectValues [0]
+			|| 'A' != (char) foo.ObjectValues [1]
+			|| "B" != (string) foo.ObjectValues [2]
+			|| EnumType.X != foo.EnumValues [0]
+			|| EnumType.Y != foo.EnumValues [1]
+			|| foo.Types [0] != typeof (int)
+			|| foo.Types [1] != typeof (Type)
+			)
+			throw new ApplicationException ();
+	}
+}
+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


More information about the mono-bugs mailing list