如何找到没有显式访问修饰符的方法?

发布于 2024-07-09 13:19:04 字数 319 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女的英雄梦 2024-07-16 13:19:04

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.

往日 2024-07-16 13:19:04

使用 FxCop 我相信执行此操作的唯一方法是编写您自己的自定义规则。 这博客文章 是一个很好的起点。

您可能还想查看 StyleCopNDepend。 我几乎可以肯定 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文