Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 2.04 KB

File metadata and controls

43 lines (31 loc) · 2.04 KB

SA1304

TypeName SA1304NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter
CheckId SA1304
Category Naming Rules

Cause

The name of a non-private readonly C# field should being with an upper-case letter.

Rule description

A violation of this rule occurs when the name of a readonly field which is not private does not begin with an upper-case letter. Non-private readonly fields should always start with an upper-case letter.

If the field or variable name is intended to match the name of an item associated with Win32 or COM, and thus needs to begin with a lower-case letter, place the field or variable within a special NativeMethods class. A NativeMethods class is any class which contains a name ending in NativeMethods, and is intended as a placeholder for Win32 or COM wrappers. StyleCop will ignore this violation if the item is placed within a NativeMethods class.

C# 8 allows readonly members on structs. This rule still only analyzes readonly fields; readonly methods, properties, indexers, or events are ignored. When a readonly field is public or protected, SA1307 reports the naming violation instead of SA1304. Static readonly fields are covered by SA1311. SA1304 normally reports on internal readonly fields (or on public/protected readonly fields only when SA1307 is disabled), which avoids multiple diagnostics for the same field.

How to fix violations

To fix a violation of this rule, change the name of the readonly field so that it begins with an upper-case letter, make the field private, or place the item within a NativeMethods class if appropriate.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1304:NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter", Justification = "Reviewed.")]
#pragma warning disable SA1304 // NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter
#pragma warning restore SA1304 // NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter