public string RenderPeople(IEnumerable<Person> people)
 {
     var personAdapter = new PersonCollectionDataAdapter(people);
     var dataRenderer = new DataRenderer(personAdapter);
     using (var sw = new StringWriter())
     {
         dataRenderer.Render(sw);
         return sw.ToString();
     }
 }
        public string PatternsList(IEnumerable <Pattern> patterns)
        {
            this.dataRenderer = new DataRenderer(new ParrentCollectionAdapter(patterns));

            var write = new StringWriter();

            this.dataRenderer.Render(write);

            return(write.ToString());
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            var adapter = new StubAdapter();

            var renderer     = new DataRenderer(adapter);
            var stringWriter = new StringWriter();

            renderer.Render(stringWriter);
            Console.WriteLine(stringWriter.ToString());

            var connection  = new SqlCeConnection(@"Data Source=db.sdf");
            var command     = new SqlCeCommand("SELECT * FROM Pattern", connection);
            var dataAdapter = new SqlCeDataAdapter(command);

            renderer     = new DataRenderer(dataAdapter);
            stringWriter = new StringWriter();
            renderer.Render(stringWriter);
            Console.WriteLine(stringWriter.ToString());

            var list = new List <Pattern>
            {
                new Pattern {
                    Id = 1, Name = "Strategy"
                },
                new Pattern {
                    Id = 2, Name = "MVC"
                }
            };
            var patternRendered = new PatternRenderer();

            Console.WriteLine(patternRendered.PatternsList(list));

            Console.WriteLine("Simple adapter pattern");
            Target target = new Target();

            target.Request();

            var adaptee = new Adapter.SimpleAdapter.Adaptee();

            target = new Adapter.SimpleAdapter.Adapter(adaptee);
            target.Request();

            Console.ReadKey();
        }