CA1506: Avoid excessive class coupling
| Value | |
|---|---|
| Rule ID | CA1506 |
| Category | Maintainability |
| Fix is breaking or non-breaking | Breaking |
Cause
A type or method is coupled with many other types. Compiler-generated types are excluded from this metric.
Rule description
This rule measures class coupling by counting the number of unique type references that a type or method contains. The default coupling threshold is 95 for types and 40 for methods.
Types and methods that have a high degree of class coupling can be difficult to maintain. It's a good practice to have types and methods that exhibit low coupling and high cohesion.
How to fix violations
To fix this violation, try to redesign the type or method to reduce the number of types to which it's coupled.
When to suppress warnings
You can suppress this warning when the type or method is considered maintainable despite its large number of dependencies on other types.
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 CA1506
// The code that's violating the rule is on this line.
#pragma warning restore CA1506
To disable the rule for a file, folder, or project, set its severity to none in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA1506.severity = none
To disable this entire category of rules, set the severity for the category to none in the configuration file.
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Maintainability.severity = none
For more information, see How to suppress code analysis warnings.
See also
Povratne informacije
Pošalјite i prikažite povratne informacije za