Usage of AttributeTargets.Delegate

266 views Asked by At

According to this stackoverflow answer you can't apply a custom attribute to an anonymous method.

What is AttributeTargets.Delegate then for?

Is it for another .NET language?

1

There are 1 answers

0
poke On BEST ANSWER

Anonymous methods are not delegates. Delegates are declarations of method types.

For example:

[AttributeUsage(AttributeTargets.Delegate)]
public class DelegateTargetAttribute : Attribute
{ }

public class Example
{
    [DelegateTarget]
    public delegate int Foo (string bar);
}