当调用Set时,有没有办法继续使用自动实现的属性,同时仍然会引发更改事件,例如INotifyPropertyChanged?
代替:
private string _value;
public string Value
{
get
{
return this._value;
}
set
{
this._value = value;
this.ValueChanged(this,EventArgs.Empty);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以这样做:
public string Value
{
get;
set
{
this.ValueChanged(this,EventArgs.Empty);
}
}
Run Code Online (Sandbox Code Playgroud)
虽然setter看起来不对,但是可以在不使用后备存储变量填充我的类的情况下执行此操作吗?
更新:看起来我的懒惰目标没有标准的解决方案,我认为最好的解决方案是使用CodeRush或Resharper为我生成所有后备存储.