Пример #1
0
        static void TestMemento()
        {
            var editor  = new Editor();
            var history = new Memento.History();

            editor.Content = "This is content 1";
            history.Push(editor.CreateState());

            editor.Content = "This is content 2";
            history.Push(editor.CreateState());

            editor.Content = "This is content 3";
            history.Push(editor.CreateState());

            editor.Content = "This is content 4";

            System.Console.WriteLine(editor.Content);

            editor.Restore(history.Pop());

            System.Console.WriteLine(editor.Content);

            editor.Restore(history.Pop());
            // editor.Restore(history.Pop());
            // editor.Restore(history.Pop());

            System.Console.WriteLine(editor.Content);
        }
Пример #2
0
        public static void Behavioral_Memento()
        {
            var editor  = new EditorM();
            var history = new Memento.History();

            editor.SetContent("A");
            history.Push(editor.CreateState());

            editor.SetContent("B");
            history.Push(editor.CreateState());

            editor.SetContent("C");
            editor.Restore(history.Pop());
            editor.Restore(history.Pop());

            Console.WriteLine(editor.GetContent());
        }