C# 如何获取第三方对象的通知';谁的财产变更事件?
我有一个名为SomeOnesClass的第三部分类对象,int属性count只有get,我无法更改或扩展该类,它没有InotificationChanged实现,如何仅通过SomeOnesClass的实例获取更改计数值的通知。尝试将SomeOnesClass放入另一个类,使用属性访问SomeOnesClass并在setter中引发事件。例如C# 如何获取第三方对象的通知';谁的财产变更事件?,c#,C#,我有一个名为SomeOnesClass的第三部分类对象,int属性count只有get,我无法更改或扩展该类,它没有InotificationChanged实现,如何仅通过SomeOnesClass的实例获取更改计数值的通知。尝试将SomeOnesClass放入另一个类,使用属性访问SomeOnesClass并在setter中引发事件。例如 class SomeOnesClassNotification : INotifyPropertyChanged { public
class SomeOnesClassNotification : INotifyPropertyChanged {
public SomeOnesClassNotification(SomeOnesClass someOnesClass) {
this.someOnesClass = someOnesClass;
}
private SomeOnesClass someOnesClass;
private int count;
public int Count {get {return count; }
set {count = value;
NotifyCountChanged();
}
}
void NotifyCountChanged() {
// Do stuff
}
public event PropertyChangedEventHandler PropertyChanged;
}
我不太确定如何实现InotificationChanged,但希望这能给您一个想法。注意,您必须使用属性或方法来访问每个SomeOnesClass成员。如果不修改SomeOnesClass,则不可能。您可能需要查看,这将允许您设置一些代码,以便为您监视更改。设置操作不是由我设置的,SomeOnesClass中没有设置计数是的,抱歉,只要读一个人,全班只有一个能手。已更新代码以反映这一点。希望这能提供一个解决方案,或者提出另一个解决方案。