Initialize field from constructor
Property | Value |
---|---|
Id | RR0197 |
Applicable Syntax | field declaration |
Syntax Span | identifier |
Enabled by Default | ✓ |
Usage
Example #1
before.cs
public class Foo
{
private string _bar;
public Foo()
{
}
public Foo(object parameter)
{
}
public Foo(object parameter1, object parameter2)
: this(parameter1)
{
}
}
after.cs
public class Foo
{
private string _bar;
public Foo(string bar)
{
_bar = bar;
}
public Foo(object parameter, string bar)
{
_bar = bar;
}
public Foo(object parameter1, object parameter2, string bar)
: this(parameter1, bar)
{
_bar = bar;
}
}
Configuration
roslynator_refactoring.initialize_field_from_constructor.enabled = true|false