我经常写下这段代码:
private int _operationalPlan;
public int OperationalPlan
{
get
{
return _operationalPlan;
}
set
{
_operationalPlan = value;
RaisePropertyChanged();
}
}
private void RaisePropertyChanged()
{
if (PropertyChanged != null)
{
PropertyChanged(this, new
PropertyChangedEventArgs("PlansSelected"));
}
}
我想知道是否可能编写一个属性,将其添加到属性中以自动触发事件。例如,类似于以下内容:
```html
我在想是否可能编写一个属性,将其添加到属性中以自动触发事件。例如,类似于以下内容:
```[RaiseOnSet("ProperyChanged", "PropertyChangedEventArgs", "PlansSelected")]
public int OperationalPlan
{
get
{
return _operationalPlan;
}
set
{
_operationalPlan = value;
RaisePropertyChanged();
}
}
在我开始尝试实现之前,我想知道:
- 这个功能在 .net 框架中吗?
- 有人尝试过这个功能吗?
- 如果可以实现吗?
- 是否需要避免任何死胡同?