Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make sure attribute is used with static methods only

Tags:

c#

attributes

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)]
like image 549
EOG Avatar asked May 21 '13 09:05

EOG


People also ask

Can attributes be static?

A static attribute is an offer field whose value is set once and does not change when the offer is used. When you create an offer template, you supply values for all static attributes.

When to use static methods javascript?

Static methods are often utility functions, such as functions to create or clone objects, whereas static properties are useful for caches, fixed-configuration, or any other data you don't need to be replicated across instances.

What is a static method?

A static method (or static function) is a method defined as a member of an object but is accessible directly from an API object's constructor, rather than from an object instance created via the constructor.


1 Answers

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

like image 74
Dave Bish Avatar answered Oct 14 '22 19:10

Dave Bish