Make sure the attribute is used only with static methods.

Is there a way to say that an attribute only works when used with static methods?

AttributeUsage class does not seem to allow such speciffic use.

 [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] 
+4
source share
2 answers

No, there is no way to limit this. However - you can use reflection at run time to ensure that this is done.

+2
source

In C # there is no such function that allows you to limit the use of attributes based on the availability of an element.

0
source

Source: https://habr.com/ru/post/1481910/


All Articles