Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.58 KB

File metadata and controls

50 lines (36 loc) · 1.58 KB

SX1309

TypeName SX1309FieldNamesMustBeginWithUnderscore
CheckId SX1309
Category Naming Rules (Alternative)

Alternative rule

This rule is a non-standard extension to the default StyleCop behavior, and represents an alternative style which is adopted by some projects. Alternative rules are known to directly conflict with standard StyleCop rules.

Cause

A field name does not begin with an underscore.

Rule description

A violation of this rule occurs when a field name does not begin with an underscore.

Detailed Behavior

This rule only checks the name of private instance fields. It ignores fields that are static, const, or have public, internal, or protected accessibility. In C# 8 and later, readonly instance members on structs (e.g. readonly methods or accessors) are not considered by this rule; only private fields—including private readonly fields—need the underscore prefix. Static readonly fields are ignored by this rule (they are treated like constants).

How to fix violations

The fix an instance of this violation, add an underscore (_) prefix to the name of the field.

Discard designations introduced by pattern matching (for example, _ in C# 8 property or positional patterns) are not considered fields and are ignored by this rule.

How to suppress violations

#pragma warning disable SX1309 // Field names should begin with underscore
int bar;
#pragma warning restore SX1309 // Field names should begin with underscore