All rules
CA1721Naming Enabled by default: No

Property names should not match get methods

Property names should not match get methods

Microsoft docs

Description

"Get" methods and properties should have names that clearly distinguish their function.

Naming conventions provide a common look for libraries that target the common language runtime. This consistency reduces the time that's required to learn a new software library and increases customer confidence that the library was developed by someone who has expertise in developing managed code.

Cause

The name of a member starts with 'Get' and otherwise matches the name of a property. For example, a type that contains a method that's named 'GetColor' and a property that's named 'Color' cause a rule violation. This rule will not fire if either the property or the method is marked with the System.ObsoleteAttribute.

By default, this rule only looks at externally visible members and properties, but this is configurable.

How to fix violations

Change the name so that it does not match the name of a method that is prefixed with 'Get'.

Example

#pragma warning disable CA1721
// The code that's violating the rule is on this line.
#pragma warning restore CA1721

When to suppress

Do not suppress a warning from this rule. One exception to that rule is if the "Get" method is caused by implementing the System.ComponentModel.IExtenderProvider interface.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0