How to pass a method as an attribute argument?

I want to apply an attribute that takes a delegate as an argument, but I cannot find the syntax for this.

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

    [SomeAttribute(typeof(SomeClass))]

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

    [SomeAttribute(??? SomeStaticMethod ???]
+5
source share
1 answer

This does not match metadata.

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

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

Naturally, you will have to refer to it through reflection, but since you are still viewing user attributes, this is probably not a big deviation.

+8
source

All Articles