Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.52 KB

File metadata and controls

47 lines (36 loc) · 1.52 KB

PH2134: Set properties in any order

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

Introduction

The user of your class should not need to know the internals of your class. This includes any behavior around the order in which you set its properties.

One sign of ordering issues in property setters is that they depend on getter of other properties that are not constants.

How to solve

Make your setters independent of other properties. If that is not possible, include the setting of the affected property in the constructor of the class.

Example

Code that triggers a diagnostic:

public class BadExample {
  public int One { get; set; }
  public int Two {
    set {
      One = value - 1;
    }
  }
}

And the replacement code:

public class GoodExample {
  public int One { get; set; }
  public int Two { get; set; }
}

Configuration

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