Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 确保属性仅用于静态方法_C#_Attributes - Fatal编程技术网

C# 确保属性仅用于静态方法

C# 确保属性仅用于静态方法,c#,attributes,C#,Attributes,有没有办法告诉属性仅在与静态方法一起使用时才起作用 AttributeUsage类似乎不允许这种特殊用法 [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] C#中没有允许您根据成员的可访问性限制属性使用的功能。不,没有办法限制此功能。但是,您可以在运行时使用反射来强制执行此操作

有没有办法告诉属性仅在与静态方法一起使用时才起作用

AttributeUsage
类似乎不允许这种特殊用法

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

C#中没有允许您根据成员的可访问性限制属性使用的功能。

不,没有办法限制此功能。但是,您可以在运行时使用反射来强制执行此操作