ReSharper 和规则集文件
我创建了一个项目并添加了一个规则集文件。然后我故意违反规则以确保它有效,但事实并非如此。
这是我启用的规则。
CA2211 - Microsoft.Usage - “非常数字段不应该 可见。”
错误代码:
public class Foo
{
public string foobar = "Hello World";
}
它编译得很好,没有警告或错误。我认为这可能与 ReSharper 覆盖它有关?我不确定。关于如何解决这个问题有什么想法吗?
I created a project and added a ruleset file. I then broke the rule on purpose to ensure that it was working, but it wasn't.
Here is the rule I enabled.
CA2211 - Microsoft.Usage -
"Non-Constant fields should not be
visible."
Bad Code:
public class Foo
{
public string foobar = "Hello World";
}
It compiles just fine, no warning or error. I think it might have to do with ReSharper overriding it? I'm not sure. Any thoughts as to how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据比较 Visual Studio 2010 产品...
如果您运行的是 VS 2010 Premium 或 Ultimate,您应该可以使用“静态代码分析”。如果是,但该功能未显示,您可以考虑重新安装 Visual Studio。抱歉,如果您没有运行其中任何一个,您将无法使用该功能。
但是,您仍然可以使用 FxCop 验证您的代码。
注意:该链接指向 FxCop 10.0。
According to Compare Visual Studio 2010 Products...
If you are running VS 2010 Premium or Ultimate you should have "Static Code Analysis" available. If you are and that feature is not showing up, you might look at reinstalling Visual Studio. If you aren't running either of those, you won't have access to that feature, sorry.
However, you can still use FxCop to validate your code.
NOTE: The link is to FxCop 10.0.
CA2211仅验证静态字段。如果您还想检查实例字段,则应启用 CA1051 (Microsoft.Design. DoNotDeclareVisibleInstanceFields)。
CA2211 only verifies static fields. If you want to check instance fields as well, you should enable CA1051 (Microsoft.Design.DoNotDeclareVisibleInstanceFields).