有没有办法自动应用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));
}
}
也许有一个扩展可以处理这个任务=)
提前感谢大家!