views:

46

answers:

1

I want to apply an attribute which accepts a delegate as an argument, but I can't find the syntax to do it.

For example, to pass a class, you have to use typeof:

    [SomeAttribute(typeof(SomeClass))]

What is the syntax for a delegate (I am trying to pass a static method)?

    [SomeAttribute(??? SomeStaticMethod ???]
+4  A: 

This is beyond the capacity of the Meta Data.

You could pass the method as a string and also specify the class if you just want to call a static method..

[SomeAttribute(typeof(SomeClass), @"SomeStaticMethod")]

Naturally you would have to invoke it through reflection, but since you are looking up the custom attributes anyway this probably isn't a big deviation.

Quintin Robinson
Well, that's too bad. I don't need this in many places, and I don't want to break refactorability. So I'll just place the method inside a class, place an attribute on the method, and target the class.
Strilanc