3

スタイル警官は、mvcWebアプリケーションのGlobal.asaxファイルのApplication_Startからアンダースコアを削除するように強制しようとします。

SP0100:メソッド(一般)名Application_Startが、指定されたスタイル:SampleNameに準拠していません。

しかし、この名前はWebアプリケーションを壊さずに変更することはできません(私は思いますか?)。

このルールをバイパスするための抑制メッセージの記述に問題があります。また、何らかの理由で、stylecopのアナライザーがこのエラーを検出しません[編集-StyleCop +エラーであるため、エラーは検出されません]-自動化できません-モジュールレベルの抑制メッセージを生成します。

誰かがこれを乗り越えるために使用する正しい抑制メッセージを手伝うことができますか?

私は次の線に沿って何かを試しました:

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

しかし運がない

4

1 に答える 1

5

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.

于 2012-02-07T20:21:18.570 に答える