What if I want to pass something into an attribute?

Topics: C# Language Design, General
Nov 7, 2014 at 8:35 AM
Edited Nov 7, 2014 at 8:39 AM
I think attributes are way too limiting. As a 3rd party developer I want to be able to make attributes that people can use however way they like, with dynamic options.

Example:

[MyAttribute(param1="mydefaultvalue")]
public void test()
{
}

Now I want a user to be able to pass something else as param1. Suggested syntax:

[param1="please do something else"]test()

This is especially needed when doing Aspect oriented programming where the methods get replaced/modified heavily by the attribute, so the need to make it more dynamic is urgent.
Feel free to paypal me some money to trusttheskygmail.com, I know how valuable my suggestions are.
Nov 7, 2014 at 3:35 PM
Are you suggesting adding attributes to method body level statements or you want to be able to omit attribute name?

Neither seem to be fitting well.

In the end of the day you probably want something like pre-processor macros.
Nov 8, 2014 at 9:50 AM
Hm I guess that would be what my suggestion amounts to. The attribute would somehow on an MSIL level need to be compiled into the method body as a hidden additional parameter on the method signature, that way we could pass anything into it.