Global.asax 中 Application_Start 的 StyleCop SP0100 错误

发布于 2025-01-02 21:54:02 字数 648 浏览 1 评论 0原文

Style cop 会尝试强制您从 mvc Web 应用程序的 Global.asax 文件中的 Application_Start 中去掉下划线:

SP0100:方法(通用)名称 Application_Start 不符合 指定样式:SampleName。

但是这个名称不能在不破坏网络应用程序的情况下更改(我认为?)。

我在编写抑制消息来绕过此规则时遇到问题,并且由于某种原因,stylecop 中的分析器没有找到此错误[编辑 - 未找到错误,因为它是 StyleCop+ error] - 所以我无法自动生成模块级抑制消息。

有人可以帮助使用正确的抑制消息来克服这个问题吗?

我尝试过以下内容:

[module: SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Scope="member", Target="Global.asax", Justification = "Some justification")]

但没有运气

Style cop will try to force you to take the underscore out of Application_Start in the Global.asax file in an mvc web application:

SP0100: Method (general) name Application_Start doesn't conform the
specified style: SampleName.

But this name cannot be changed without breaking the web application (I think?).

I am having trouble writing the suppress message to bypass this rule, and also for some reason the analyzer in stylecop is not finding this error [Edit - the error is not being found because it is a StyleCop+ error] - so I am unable to auto-generate a module-level suppress message.

Can someone help with the right suppress message to use to get past this?

I have tried something along the lines of:

[module: SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Scope="member", Target="Global.asax", Justification = "Some justification")]

But with no luck

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

陌路终见情 2025-01-09 21:54:02

首先,StyleCop 抑制确实很难记住,但最简单的方法是在你的方法之前或整个类之前使用它们。在您的情况下,抑制属性将如下所示:

[SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Justification = "Global ASAX method.")]

其次,StyleCop+ 目前无法检测全局 ASAX 方法,因此它将它们视为常用方法并应用相应的规则。鉴于此,您可能可以对“方法(常规)”使用以下命名规则:

$(AaBb)
Application_$(AaBb)
Page_$(AaBb)
Session_$(AaBb)

这里的缺点是方法 Application_DoWork 不会被违反,即使它与 Global ASAX 无关。

最后,您可以向 StyleCop+ 提交问题,以便它可以区分全局 ASAX 方法并对其应用单独的命名规则。

First, StyleCop suppressions are hard to remember indeed, but the easiest way is to use them just right before your method, or before the whole class. In your case suppression attribute will look like:

[SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Justification = "Global ASAX method.")]

Second, StyleCop+ is not currently able to detect Global ASAX methods, so it considers them as common methods and apply corresponding rules. Given that, you could probably use the following naming rules for "Methods (general)":

$(AaBb)
Application_$(AaBb)
Page_$(AaBb)
Session_$(AaBb)

The disadvantage here is that method Application_DoWork will not be violated, even it is not related to Global ASAX.

Finally, you could submit an issue to StyleCop+, so that it could distinguish Global ASAX methods and apply separate naming rules to them.

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