| Property | Value |
|---|---|
| Package | Philips.CodeAnalysis.MaintainabilityAnalyzers |
| Diagnostic ID | PH2126 |
| Category | Maintainability |
| Analyzer | AvoidUsingParametersAsTempVariablesAnalyzer |
| CodeFix | No |
| Severity | Error |
| Enabled By Default | Yes |
Inside a method, do not assign a new value to the methods parameter variable. This makes a method's code harder to read as you're (indirectly) assigning a new role to the variable.
Introduce a local variable instead of changing the parameter variable.
Code that triggers a diagnostic:
public class BadExample {
public void BadCode(int number) {
number = 2;
}
}And the replacement code:
public class GoodExample {
public void GoodCode(int number) {
int myNumber = 2;
}
}ref and out parameters are allowed to be assigned to as that is part of their expected behavior.
This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.