Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Author author = new Author();
            author.FullName = "Gang of Four";
            author.Age = 22;

            Blog blog = new Blog();
            blog.Id = 1;
            blog.Name = "Design Patterns";
            blog.Comments.Add("Visitor pattern");
            blog.Comments.Add("Abstract factory pattern");
            blog.Comments.Add("Composite pattern");
            blog.Author = author;

            ISerializerFactory serializerFactory = new UnicodeXmlSerializerFactory();
            var service = new BlogDataExchangeService();
            service.SerializerFactory = serializerFactory;

            System.Console.WriteLine("{0}:\n{1}\n", "Full as Unicode XML Document", service.GetFull(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Header as Unicode XML Document", service.GetHeader(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Exchange as Unicode XML Document", service.GetFullForExchange(blog));

            System.Console.WriteLine();

            serializerFactory = new JsonSerializerFactory();
            service.SerializerFactory = serializerFactory;

            System.Console.WriteLine("{0}:\n{1}\n", "Full as JSON Document", service.GetFull(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Header as JSON Document", service.GetHeader(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Exchange as JSON Document", service.GetFullForExchange(blog));

            System.Console.WriteLine("Execution finished. Press a key to exit.");
            System.Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Author author = new Author();

            author.FullName = "Gang of Four";
            author.Age      = 22;

            Blog blog = new Blog();

            blog.Id   = 1;
            blog.Name = "Design Patterns";
            blog.Comments.Add("Visitor pattern");
            blog.Comments.Add("Abstract factory pattern");
            blog.Comments.Add("Composite pattern");
            blog.Author = author;

            ISerializerFactory serializerFactory = new UnicodeXmlSerializerFactory();
            var service = new BlogDataExchangeService();

            service.SerializerFactory = serializerFactory;

            System.Console.WriteLine("{0}:\n{1}\n", "Full as Unicode XML Document", service.GetFull(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Header as Unicode XML Document", service.GetHeader(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Exchange as Unicode XML Document", service.GetFullForExchange(blog));

            System.Console.WriteLine();

            serializerFactory         = new JsonSerializerFactory();
            service.SerializerFactory = serializerFactory;

            System.Console.WriteLine("{0}:\n{1}\n", "Full as JSON Document", service.GetFull(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Header as JSON Document", service.GetHeader(blog));
            System.Console.WriteLine("{0}:\n{1}\n", "Exchange as JSON Document", service.GetFullForExchange(blog));

            System.Console.WriteLine("Execution finished. Press a key to exit.");
            System.Console.ReadLine();
        }