Domanda

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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top