示例#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());
        }
        static void Main(string[] args)
        {
            var editor  = new Editor();
            var history = new History();

            editor.Content = "a";
            history.Push(editor.CreateState());
            editor.Content = "b";
            history.Push(editor.CreateState());

            editor.Content = "c";
            editor.Restore(history.Pop());

            Console.WriteLine(editor.Content);

            editor.Restore(history.Pop());
            Console.WriteLine(editor.Content);

            Console.Read();
        }