Notify changes when external parameters change

I need to attach a notification change event to an encapsulated parameter in an external class. Normally, I would use INotifyPropertyChanged , but I cannot edit the outer class. What is the correct approach to this problem?

+6
source share
2 answers

It will be very difficult to do. It seems like the best option is to output this class, but you need all properties to be marked virtual . When you have no control over a class that seems unlikely.

If you're the only one calling this class, you can also create a wrapper that mimics the behavior of this class. You can create properties yourself and implement INotifyPropertyChanged . However, you cannot receive notification of a change to an internal object.

If this is your best option, you can also implement an implicit conversion operator so that you can pass in your class as if it were the class you are wrapping.

+1
source

A brute-force approach may be to use a timer that constantly looks at the value of this property (say) for 1 second and notifies you when the value of the property does not match the previous one. Timers use light streams on their own, so this should not be a heavy load on resources. Looking at the difficult situation you are in, this seems to be the only viable option.

0
source

Source: https://habr.com/ru/post/973701/


All Articles