Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.47 KB

File metadata and controls

47 lines (35 loc) · 1.47 KB

PH2126: Avoid using Parameters as temporary variables

Property Value
Package Philips.CodeAnalysis.MaintainabilityAnalyzers
Diagnostic ID PH2126
Category Maintainability
Analyzer AvoidUsingParametersAsTempVariablesAnalyzer
CodeFix No
Severity Error
Enabled By Default Yes

Introduction

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.

How to solve

Introduce a local variable instead of changing the parameter variable.

Example

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;
  }
}

Exceptions

ref and out parameters are allowed to be assigned to as that is part of their expected behavior.

Configuration

This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.