Reputation: 1936
How can I set up in StyleCop rules that all private fields must begin with underscore _
?
Upvotes: 11
Views: 4743
Reputation: 295
SX1309FieldNamesMustBeginWithUnderscore
StyleCop rule gets the job done.
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SX1309.md
This rule can be configured with action error
in ruleset file as below to achieve the desired objective.
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SX1309" Action="Error" />
</Rules>
Upvotes: 4
Reputation: 1349
You could take a look at StyleCop+ with its flexible naming rules. It is open-source, so you could also use it for writing your own custom rules.
P.S. A similar question: Find out if CsElement is a static field? (StyleCop custom rule)
Upvotes: 4