These are the most common and only patterns I have seen so far:
[AttributeFoo]
[AttributeBar("Hello world!")]
[AttributeBaz(foo=42,bar="Hello world!")]
public class Example {}
The attribute syntax looks like you’re calling a constructor. And before C# supported optional and named arguments, named parameters for attributes were the only visible difference.
Does the C# compiler allow anything else? Like params arguments or object/collection initializers?
See also: Applying Attributes on MSDN
AFAIK, named parameters only permit integral types. Unfortunately i do not have a reference to back this up, I only learnt it through my own experimentation.
When trying to use object initialisers, I got this error from the compiler:
Although this documentation is a few years old, it has the reference information I was looking for:
So this works:
Whereas this wouldn’t:
EDIT: just to elaborate, attributes form part of the metadata for constructs they are applied to (within the generated IL), thus the members of the attribute class must be determined at compile time; hence the restriction on attribute parameters to constant values.