[Mono-list] C# Attributes in Mono

A Rafael D Teixeira rafaelteixeirabr@hotmail.com
Wed, 29 Jan 2003 00:35:16 -0200


>From: Hamza Karamali <karamal@eecg.toronto.edu>

>I'm new to Mono: I just downloaded and installed it yesterday, and I'm
>currently trying to run a couple of programs that compile and run on
>"normal" Windows .NET.  One of my programs uses attributes that take
>various kinds of arguments:
>
>	[myAttribute("stringArgument", (String)null, (String)null, 2)]
>
>And when compiling the code, I get the following error message:
>
>	myCode.cs(204) error CS0182: An attribute argument must be a constant
>	expression, typeof expression or array creation expression
>	myCode.cs(221) error CS0182: An attribute argument must be a constant
>	expression, typeof expression or array creation expression
>	Compilation failed: 2 error(s), 0 warnings
>
>Does anyone know why this happens?

I tested with mono-0.19's mcs and with csc, and so it seems like it is bug 
in mcs. Please fill a bug report in mono's bugzilla.

As a note: design CLR attributes with multiple constructors, to avoid having 
to pass null parameters when they can be ommited.

Also: eliminating the cast to string in the null values, makes the error 
message go away. This form compiles ok with mcs:

[myAttribute("stringArgument", null, null, 2)]

That typecasts are only needed if you have similar constructors for the 
attribute that may confuse the compiler if not guided by the typecasts.

Happy hackings,

Rafael Teixeira
Brazilian Polymath
Mono, MonoQLE Hacker






_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail