Επεξεργασία

Κοινή χρήση μέσω


CA1725: Parameter names should match base declaration

Property Value
Rule ID CA1725
Title Parameter names should match base declaration
Category Naming
Fix is breaking or non-breaking Breaking
Enabled by default in .NET 9 No

Cause

The name of a parameter in a method override does not match the name of the parameter in the base declaration of the method or the name of the parameter in the interface declaration of the method.

By default, this rule only looks at externally visible methods, but this is configurable.

Rule description

Consistent naming of parameters in an override hierarchy increases the usability of the method overrides. A parameter name in a derived method that differs from the name in the base declaration can cause confusion about whether the method is an override of the base method or a new overload of the method.

How to fix violations

To fix a violation of this rule, rename the parameter to match the base declaration. The fix is a breaking change for COM visible methods.

When to suppress warnings

Do not suppress a warning from this rule except for COM visible methods in libraries that have previously shipped.

Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

[*.{cs,vb}]
dotnet_diagnostic.CA1725.severity = none

For more information, see How to suppress code analysis warnings.

Configure code to analyze

Use the following option to configure which parts of your codebase to run this rule on.

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category (Naming) that it applies to. For more information, see Code quality rule configuration options.

Include specific API surfaces

You can configure which parts of your codebase to run this rule on, based on their accessibility. For example, to specify that the rule should run only against the non-public API surface, add the following key-value pair to an .editorconfig file in your project:

dotnet_code_quality.CAXXXX.api_surface = private, internal