public void BeginCompoundDo(int pointerIndex) { if (tempMemento != null) { throw new InvalidOperationException("Previous complex memento wasn't commited."); } tempMemento = new CompoundListMemento <T, U>(pointerIndex); }
public void EndCompoundDo() { if (tempMemento == null) { throw new InvalidOperationException("Ending a non-existing complex memento"); } _Do(tempMemento); tempMemento = null; }
public CompoundListMemento <T, U> Restore(T target) { CompoundListMemento <T, U> inverse = new CompoundListMemento <T, U>(pointerIndex); //starts from the last action for (int i = mementos.Count - 1; i >= 0; i--) { inverse.Add(mementos[i].Restore(target)); } return(inverse); }