Automatically apply C# 7 getter and setter style

769 views Asked by At

Is there any way to automatically apply C# 7 getter and setter styles (or maybe other new language features)?

It would be nice if there would be any way to automatically change properties like these:

public string MyProperty1
{
    get
    {
        return this.myProperty1;
    }
}

public string MyProperty2
{
    get
    {
        return this.GetSomething();
    }
    set
    {
        this.SetSomething(value);
    }
}

public string MyProperty3
{
    get
    {
        return this.myProperty3;
    }
    set
    {
        this.myProperty3 = value;
        this.RaisePropertyChange(nameof(MyProperty3));
    }
}

to this:

public string MyProperty1 => this.myProperty1;

public string MyProperty2
{
    get => this.GetSomething();
    set => this.SetSomething(value);
}

public string MyProperty3
{
    get => this.myProperty3;
    set
    {
        this.myProperty3 = value;
        this.RaisePropertyChange(nameof(MyProperty3));
    }
}

Maybe there is an extension which can handle this task =)

Thanks everybody in advance!

1

There are 1 answers

4
Antoshjke On BEST ANSWER

Use Resharper for this. Resharper