public void StackUndoToDepth (int depth) { if (undoStack.Count == depth) return; var atomicUndo = new AtomicUndoOperation (); while (undoStack.Count > depth) { atomicUndo.Operations.Insert (0, undoStack.Pop ()); } undoStack.Push (atomicUndo); }