如何找到没有显式访问修饰符的方法?
我正在使用 FxCop,我想找到所有没有显式定义访问修饰符的方法或变量。 例如:
class MyClass
{
int myInt = 0;
internal MyClass()
{
}
}
我希望 FxCop 警告我,我没有指定什么访问修饰符将应用于变量“myInt”或类“MyClass”。 以前有人这样做过吗,或者有人可以提供从哪里开始的指导吗?
更新:只是为了让大家知道,查找此内容的 StyleCop 规则是SA1400。
I am using FxCop and I would like to find all the methods or variables without an access modifier explicitly defined. For example:
class MyClass
{
int myInt = 0;
internal MyClass()
{
}
}
I would like FxCop to warn me that I didn't specify what access modifier will be applied to the variable "myInt" or the class "MyClass". Has anyone done this before, or can anyone offer guidance on where to start?
Update: Just to let everyone know, the StyleCop rule that looks for this is SA1400.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FxCop 分析已编译的代码,其中应用了访问修饰符。 您需要使用 StyleCop 等工具来检测编码语法问题,例如未显式声明访问修饰符。
FxCop analyses the compiled code, which has access modifiers applied. You need to use a tool like StyleCop to detect coding syntax issues such as not explicitly declaring access modifiers.
使用 FxCop 我相信执行此操作的唯一方法是编写您自己的自定义规则。 这博客文章 是一个很好的起点。
您可能还想查看 StyleCop 和 NDepend。 我几乎可以肯定 NDepend 会执行此操作(尽管您可能需要编写一些自定义 CQL),并且我知道 StyleCop 会开箱即用地执行此操作。
Using FxCop I beleive the only way to do this would be to write your own custom rule. This blog post is a good place to start.
You may also want to take a look at StyleCop and NDepend. I'm almost certain NDepend will do this (although you may have to write some custom CQL) and I know StyleCop will do this out of the box.