public void Undo() { if (_mementos.Count == 0) { return; } var memento = _mementos.Last(); _mementos.Remove(memento); try { _originator.Restore(memento); } catch (Exception) { Undo(); } }
// Order to restore a previous state. public void Undo() { if (_mementoes.Count == 0) { return; } var memento = _mementoes.Last(); _mementoes.Remove(memento); try { _originator.Restore(memento); } catch (Exception e) { // If an exception occurs, try again with the next memento. Console.WriteLine(e); Undo(); } }
public void Undo() { originator.Restore(history.Last()); history.RemoveAt(history.Count - 1); }