예제 #1
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Init sales prospect through object initialization
            SalesProspect s = new SalesProspect
                      {
                          Name = "Joel van Halen",
                          Phone = "(412) 256-0990",
                          Budget = 25000.0
                      };

            // Store internal state
            ProspectMemory m = new ProspectMemory();
            m.Memento = s.SaveMemento();

            // Change originator
            s.Name = "Leo Welch";
            s.Phone = "(310) 209-7111";
            s.Budget = 1000000.0;

            // Restore saved state
            s.RestoreMemento(m.Memento);

            // Wait for user
            Console.ReadKey();
        }
예제 #2
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Init sales prospect through object initialization
            SalesProspect s = new SalesProspect
            {
                Name   = "Joel van Halen",
                Phone  = "(412) 256-0990",
                Budget = 25000.0
            };

            // Store internal state
            ProspectMemory m = new ProspectMemory();

            m.Memento = s.SaveMemento();

            // Change originator
            s.Name   = "Leo Welch";
            s.Phone  = "(310) 209-7111";
            s.Budget = 1000000.0;

            // Restore saved state
            s.RestoreMemento(m.Memento);

            // Wait for user
            Console.ReadKey();
        }
예제 #3
0
        // Restores (deserializes) memento
        public void RestoreMemento(Memento memento)
        {
            Console.WriteLine("\nRestoring state --\n");

            SalesProspect s = (SalesProspect)memento.Deserialize();

            this.Name   = s.Name;
            this.Phone  = s.Phone;
            this.Budget = s.Budget;
        }