public static void RunExercise() { var history = new DocumentHistory(); var doc = new Document { Content = "The Title", FontName = "Times New Roman", FontSize = 12 }; history.Push(doc.CreateState(doc)); doc = new Document { Content = "The Body", FontName = "Times New Roman", FontSize = 11 }; history.Push(doc.CreateState(doc)); Console.WriteLine($"State After Save: {doc.ToString()}"); doc = new Document { Content = "The Footer", FontName = "Times New Roman", FontSize = 14 }; doc.RestoreState(history.Pop()); Console.WriteLine($"State After Restore: {doc.ToString()}"); }
private static void Main() { var history = new DocumentHistory(); Document document = new Document("Content 1"); Console.WriteLine("Original document:"); Console.WriteLine(document.Content); var currentState = document.GetState(); history.History.Push(currentState); document.Content = "Content 2"; Console.WriteLine("Modified document:"); Console.WriteLine(document.Content); var previousState = history.History.Pop(); document.Undo(previousState); Console.WriteLine("Restored document:"); Console.WriteLine(document.Content); }