This is the online documentation for PostSharp 4.3.
Download PDF or CHM. Go to v4.3 or v5.0
Adding Callbacks on Undo and Redo

You may run into situations where you will want to execute some code before or after an object is being modified by an Undo or Redo operation. This capability is provided through the IRecordableCallback interface.

In the following example, we will show how to integrate the RecordableAttribute aspect with a custom implementation of INotifyPropertyChanged (the standard NotifyPropertyChangedAttribute aspect is already integrated with the RecordableAttribute aspect so you don't need to worry).

C#
[Recordable]
public class Invoice : INotifyPropertyChanged, IRecordableCallback
{
  public void OnReplaying(ReplayKind kind, ReplayContext context)
  {
  }

  public void OnReplayed(ReplayKind kind, ReplayContext context)
  {
    OnPropertyChanged("ShippingDate");
  }

  private DateTime _shippingDate;
  public DateTime ShippingDate 
  {
    get { return _shippingDate; }
    set 
    {
      _shippingDate = value;
       OnPropertyChanged("ShippingDate");
    }
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(string propertyName = null)
  {
      var handler = PropertyChanged;
      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
  }    
}

For more information, see the reference documentation for the IRecordableCallback interface.