示例#1
0
        static void Main(string[] args)
        {
            IAuthotSerializer mySerializer = new CustomTextSerializer();
            List <Book>       books        = new List <Book>();

            books.Add(new Book()
            {
                Title = "Djek London", PublishDate = DateTime.Now
            });
            books.Add(new Book()
            {
                Title = "Linux CentOS", PublishDate = DateTime.Now
            });
            books.Add(new Book()
            {
                Title = "Story of Me", PublishDate = DateTime.Now
            });

            Author author = new Author()
            {
                Name = "Author Name", Books = books, Email = "*****@*****.**"
            };

            mySerializer.Serializing(author, "me1.txt");
            Author myTest = mySerializer.Deserializing("me1.txt");

            Console.WriteLine(myTest.Name);
            Console.WriteLine(myTest.Email);
            Console.WriteLine("Number of books {0}", myTest.Books.Count);
            foreach (var book in myTest.Books)
            {
                Console.WriteLine("{0}:{1}", book.Title, book.PublishDate.ToShortDateString());
            }
            Console.WriteLine();
        }
示例#2
0
        public static void Main()
        {
            // IAuthorSerializer mySerializer = new AuthorSerializer();

            IAuthorSerializer mySerializer = new CustomTextSerializer();

            List<Book> books = new List<Book>();
            books.Add(new Book() { Title = "Harry Potter", PublishDate = DateTime.Now });
            books.Add(new Book() { Title = "Intro to programming", PublishDate = DateTime.Now });
            books.Add(new Book() { Title = "Lineage", PublishDate = DateTime.Now });

            Author author = new Author() { Name = "Pesho", Books = books, Email = "*****@*****.**" };

            mySerializer.Serializing(author, "pesho.txt");
            Author pesho = mySerializer.Deserializing("pesho.txt");

            Console.WriteLine(pesho.Name);
            Console.WriteLine(pesho.Email);
            Console.WriteLine("Books Count: " + pesho.Books.Count);
            foreach (var book in pesho.Books)
            {
                Console.WriteLine("- {0} : {1}", book.Title, book.PublishDate.ToShortDateString());
            }
        }