If property is already being assigned on constructor, don't raise a diagnostic.
Offer the diagnostic if the class has:
- No constructors. Offer two code fixes:
- Create the constructor initializing the property.
- Create the constructor initializing the property and create a default constructor. This will keep existing code from breaking.
- One constructor. If the existing constructor is not the default constructor update this constructor. If it is, offer 2 code fixes:
- Update the existing constructor.
- Create a new parametrized constructor that calls the default constructor. This will keep existing code from breaking.
- Two constructors, and one of them is the default constructor. Update the constructor that is not the default one. If the property is initialized on the default constructor or the non default constructor, don't raise the diagnostic. If neither of the constructors is the default one don't raise any diagnostic.
Existing constructions of this object are expected to break in some of these scenario.
Examples (not all of the above rules are exemplified):
This:
class Foo
{
public int Bar { get; set; }
}
Becomes:
class Foo
{
public Foo(int bar)
{
this.Bar = bar;
}
public int Bar { get; set; }
}
If the constructor already exists, add to it:
This:
class Foo
{
public Foo()
{
}
public int Bar { get; set; }
}
Becomes:
class Foo
{
public Foo(int bar)
{
this.Bar = bar;
}
public int Bar { get; set; }
}
Diagnostic Id: CC0083
Severity: Hidden
Category: Refactoring
If property is already being assigned on constructor, don't raise a diagnostic.
Offer the diagnostic if the class has:
Existing constructions of this object are expected to break in some of these scenario.
Examples (not all of the above rules are exemplified):
This:
Becomes:
If the constructor already exists, add to it:
This:
Becomes:
Diagnostic Id:
CC0083Severity: Hidden
Category: Refactoring