using System.Collections.Generic;
public static void Main()
public static void RunModel()
List<UndoBatch> um = new List<UndoBatch>();
batch.AddUndoData( new ChangeQuantityUndoData() );
batch.AddUndoData( new ChangeQuantityUndoData() );
batch.AddUndoData( new ChangeQuantityUndoData() );
batch.AddUndoData( new ChangePriceUndoData() );
batch.AddUndoData( new ChangePriceUndoData() );
batch.AddUndoData( new AddProductUndoData() );
DeleteProductUndoData dpud = new DeleteProductUndoData();
dpud.DeletedElementRestoredEventHandler += (sender, e) => { Console.WriteLine("Undo: Restored Product = {0}", ((DeleteProductUndoData)e).originalId); };
batch.AddUndoData( dpud );
foreach (UndoBatch ub in um)
public static void OnDeletedElementRestored(object sender, DeleteProductUndoData e)
Console.WriteLine("Undo: Restored Product = {0}", e.originalId);
private List<IUndoData> operationData;
operationData = new List<IUndoData>();
public void AddUndoData(IUndoData undoData)
operationData.Add(undoData);
public void RunUndoBatch()
foreach (IUndoData op in operationData)
public class ChangeQuantityUndoData : IUndoData
Console.WriteLine("Undo: Change Quantity");
public class ChangePriceUndoData : IUndoData
Console.WriteLine("Undo: Change Price");
public class AddProductUndoData : IUndoData
Console.WriteLine("Undo: Add Product");
public class DeleteProductUndoData : IUndoData
public EventHandler<IUndoData> DeletedElementRestoredEventHandler;
Console.WriteLine("Undo: Delete Product");
if (DeletedElementRestoredEventHandler != null)
DeletedElementRestoredEventHandler.Invoke(this, this);
public int originalId { get; set; }
public interface IUndoData