Search code examples
postsharp

Postsharp Recordable and NotifyPropertyChanged


I am using the "standard" NotifyPropertyChanged aspect in combination with Recordable, which works fine.

Now I want to check the changes for my custom dirty logic. To do so, I have written a custom aspect that uses

[OnLocationSetValueAdvice, MulticastPointcut(Targets = MulticastTargets.Property)]
public void OnPropertySet(LocationInterceptionArgs args)

This method gets called when manually changing a property, but is not called on performing an undo, which seems strange to me.

How can I catch changes coming from undo, too?


Solution

  • PostSharp's [Recordable] records change on the level of fields, not of properties, and therefore your aspect is skipped during undo/redo. You should apply it to fields and order it after Recordable.

    Alternatively, you can implement the callback interface.