public void Undo() { if (_mementos.Count == 0) { return; } IMemento memento = _mementos.Last(); _mementos.Remove(memento); Console.WriteLine("Caretaker: Restaurando estado a: " + memento.GetName()); try { _originator.Restore(memento); } catch (Exception) { Undo(); } }
/// <summary> /// Cancel the action, the command will return the object to its previous state. /// </summary> public void Undo() { if (_mementos.Count == 0) { return; } IMemento memento = _mementos.Last(); _mementos.Remove(memento); Console.WriteLine($"\nSupplierMemory: Restoring state to: {memento.GetName()}"); try { _foodSupplier.RestoreMemento(memento); } catch (Exception) { Undo(); } }