Open sandboxFocusImprove this doc

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 output a message each time an undo or redo operation executes.

[Recordable]
public class Invoice : IRecordableCallback
{
  public void OnReplaying(ReplayKind kind, ReplayContext context)
  {
      if (kind == ReplayKind.Redo) {
           Console.WriteLine("I will now redo a previously undone change to the shipping date.");
      }
  }
  
  public void OnReplayed(ReplayKind kind, ReplayContext context)
  {
      if (kind == ReplayKind.Undo) {
           Console.WriteLine("A change to the shipping date is now undone.");
      }
  }
  
  public DateTime ShippingDate { get; set; }   
}

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