1

I need to capture old and new value in PropertyChanged event handler. I have already implemented a solution for this using C# INotifyPropertyChanged interface. You can refer below question for solution that I have implemented:

How to capture old value and new value in INotifyPropertyChanged implementation of PropertyChanged event in C#

I was evaluating if this can be done using PostSharp. Because with current solution, auto properties will not work.

Thanks in advance for your help.

Umesh

Umesh Kanase
  • 83
  • 1
  • 5

1 Answers1

0

By definition INotifyPropertyChanged interface deals with notification AFTER the value has changed and INotifyPropertyChanging interface deals with notification BEFORE the value has changed. [NotifyPropertyChanged] aspect implements both for you but does not provide a way to do what you want out of the box.

Further it postpones notifications until a more complex change on the same object, this both lowers number of notifications and makes sure that when notification occurs, the object is in correct state (think of a method changing several properties on the object) for the code that reacts to the notification (this does not apply to INotifyPropertyChanging). More about the implementation details here.

You would need to implement an aspect that would implement your interface and would register itself for INotifyPropertyChanged and INotifyPropertyChanging, recording property values on each changing notification and using those recorded values on changed notification to raise your own event.

You would probably need to do the following:

It does not seem as a complex aspect but you would definitely need to familiarize yourself with advanced concepts of PostSharp's Aspect Framework.

Daniel Balas
  • 1,805
  • 1
  • 15
  • 20