コード例 #1
0
 public Memento(Book book)
 {
     ISBN = book.ISBN;
     Title = book.Title;
     Author = book.Author;
     LastEdited = book.LastEdited;
 }
コード例 #2
0
        public void TestMethod1()
        {
            Book book = new Book();
            book.ISBN = "0450488357";
            book.Title = "The Tommyknockers";
            book.Author = "Stephen King";
            book.ShowBook();

            book.SaveUndo();

            Thread.Sleep(1000);

            // Modify book
            book.ISBN = "0330376144";
            book.Title = "The Rats";
            book.Author = "James Herbert";
            book.ShowBook();

            book.SaveUndo();

            book.PrintHistory();

            book.RestoreToVersion(1);
            book.ShowBook();
        }
コード例 #3
0
 private static void RestoreBook(Book book, Memento memento)
 {
     if (memento != null && book != null)
     {
         book.RestoreFromUndo(memento);
     }
 }
コード例 #4
0
 public void SaveUndo(Book book)
 {
     _history.Add(book.CreateUndo());
 }
コード例 #5
0
        public void RestoreToVersion(Book book, int versionNumber)
        {
            var memento = _history.FirstOrDefault(mem => mem.VersionNumber == versionNumber);

            RestoreBook(book, memento);
        }
コード例 #6
0
        public void RestoreToLatestVersion(Book book)
        {
            var memento = History.LastOrDefault();

            RestoreBook(book, memento);
        }