Reputation: 63
I need to attach a notify change event to an encapsulated parameter in an external class. I usually would implement INotifyPropertyChanged
, but I can't edit the external class. What is the right approach for this problem?
Upvotes: 6
Views: 400
Reputation: 35460
A brute force approach could be to use a timer which keeps looking at the value of that property every (say) 1 second and notifies you when the property value is not the same as the previous read. Timers use light-weight threads of their own, so this shouldn't be a lot of burden on the resources either. Looking at the tough situation that you're in, this seems to be the only viable option.
Upvotes: 0
Reputation: 157136
That will be very hard to do. The best option seems to be deriving that class, but you need all properties to be marked virtual
. When you have no control over the class that seems to be unlikely.
If you are the only one calling that class, you could also create a wrapper that mimics that class' behavior. You could create properties yourself and implement INotifyPropertyChanged
. You can't get notified on changed to the inner object though.
If that is your best option, you could also implement a implicit conversion operator so you can pass in your class like it was the class you are wrapping.
Upvotes: 1