EOG
EOG

Reputation: 1747

Make sure attribute is used with static methods only

Is there a way to tell attribute to work only when used with static methods?

AttributeUsage class does not seem to allow such specyfic usage.

[AttributeUsage(AttributeTargets.Method,
                Inherited = false, AllowMultiple = false)]

Upvotes: 10

Views: 3308

Answers (2)

Dave Bish
Dave Bish

Reputation: 19646

No, there is no way to restrict this. However - you could use reflection at run-time to enforce this.

Upvotes: 5

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

There is no such feature available in C# that allows you to restrict attribute usage based on a member's accessibility.

Upvotes: 1

Related Questions