RefactoringEssentials icon indicating copy to clipboard operation
RefactoringEssentials copied to clipboard

Feature request: Refactor to initialize instance through ctor

Open bexxx opened this issue 9 years ago • 1 comments

class C {

public int I1 { get; set; } public int I2 { get; set; } }

should be refactored to class C { public C(int i1, int i2) { this.I1 = i1; this.I2 = i2; }

public int I1 { get; set; } public int I2 { get; set; } }

optionally making setters private :), althrough this would mean to fix all ctor call sites. So maybe not.

This refactoring could help to make types immutable.

bexxx avatar Aug 12 '16 07:08 bexxx

This is my most used feature in Resharper.

public class Foo {
    public string Bar { get; }
}

To

public class Foo {
    public Foo(string bar) {
        Bar = bar;
    }

    public string Bar { get; }
}

Yavari avatar Mar 11 '17 14:03 Yavari