自动应用C#7 getter和setter样式

时间:2017-09-07 12:57:30

标签: c# coding-style getter-setter language-features c#-7.0

有没有办法自动应用C#7 getter和setter样式(或者其他新语言功能)?

如果有任何方法可以自动更改这些属性,那将会很好:

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));
    }
}

到此:

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));
    }
}

也许有一个扩展可以处理这个任务=)

提前感谢大家!

1 个答案:

答案 0 :(得分:-1)

使用Resharper。 Resharper