【发布时间】:2016-09-19 12:37:23
【问题描述】:
我有一个关于观察对象属性的问题。
例如,我有一个这样的类:
public class MyProperties
{
public string Prop1 { get; set; }
public int Prop2 { get; set; }
}
我希望在 MyProperties 的属性之一发生更改时收到通知。我的愿景是这样的:
//I have an instance
MyProperties Prop = new Myproperties();
//And add a listener to the properties
Prop.Prop1.AddNotification(APropertyChanged);
Prop.Prop2.AddNotification(APropertyChanged);
//I have a eventhandler in my code
public void (object Sender, EventArgs e)
{
//Sender is the Property
}
我不想更改 MyProperties 中的任何代码。有没有办法实现这样的目标.. 还是这个想法完全是白痴?
【问题讨论】:
标签: c# events notifications observer-pattern observers