Skip to main content

Initialize field from constructor

PropertyValue
IdRR0197
Applicable Syntaxfield declaration
Syntax Spanidentifier
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