Question

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 ???]
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top