Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        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.Restore(history.Pop());

            Console.WriteLine(history.Peek().Content);
        }
Ejemplo n.º 3
0
        private static void Main()
        {
            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);
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var editor  = new Editor();
            var history = new History();

            editor.Content = "article 1";
            history.Push(editor.CreateState());

            editor.Content = "article 2";
            history.Push(editor.CreateState());

            editor.Content = "article 3";
            history.Push(editor.CreateState());

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

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

            Console.ReadKey();
        }