Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.79 KB

SA1308.md

File metadata and controls

43 lines (31 loc) · 1.79 KB

SA1308

TypeName SA1308VariableNamesMustNotBePrefixed
CheckId SA1308
Category Naming Rules

Cause

A field name in C# is prefixed with m_ or s_.

Rule description

A violation of this rule occurs when a field name is prefixed by m_ or s_.

By default, StyleCop disallows the use of underscores, m_, etc., to mark local class fields, in favor of the 'this.' prefix. The advantage of using 'this.' is that it applies equally to all element types including methods, properties, etc., and not just fields, making all calls to class members instantly recognizable, regardless of which editor is being used to view the code. Another advantage is that it creates a quick, recognizable differentiation between instance members and static members, which will not be prefixed.

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 the prefix, 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.

How to fix violations

To fix a violation of this rule, remove the prefix from the beginning of the field name, or place the item within a NativeMethods class if appropriate.

How to suppress violations

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