How to implement the property of a modified notification without an explicit call?

In WPF, there is the concept of two-way data binding, where when the value of an object property is updated in db, it also updates the view when the INotifyPropertyChanged interface is INotifyPropertyChanged .

I am looking for something like this function in C # but I am not using WPF.

The scenario is that when the property of an object is updated, a series of notifications is sent to other users of this object, notifying them of a change in the property.

So the thread:

  • Database update
  • Notify Consumer 1
  • Notify Consumer 2

This process requires three separate lines. Is there a way to implement the WPF concept for a property modified for an update, no matter who the consumer (say, event driven) is without having to explicitly notify consumers?

+1
source share
1 answer

When implementing INotifyPropertyChanged you simply raise an event when you want to inform consumers that the property has changed. You only make one call to pick up an event no matter how many consumers listen to this event.

If what you are trying to achieve is to reduce the template code, i.e. having only one line of code for the setter, you can take a look at this simple solution , which can be done even better with C # 5 .

+1
source

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


All Articles