Search code examples
c#coding-stylegetter-setterlanguage-featuresc#-7.0

Automatically apply C# 7 getter and setter style


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!


Solution

  • Use Resharper for this. Resharper