示例#1
0
        // Faceted Builder Example
        public static void FacetedBuilder()
        {
            var pb = new FacetedBuilder.PersonBuilder();

            FacetedBuilder.Person person = pb
                                           .Lives.At("123 london Road")
                                           .In("London")
                                           .WithPostcode("SW12AC")
                                           .Works.At("Fabrikam")
                                           .AsA("Engineer")
                                           .Earning(1234567);

            WriteLine(person);
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("Classic Builder:");
            Console.WriteLine();

            var builder = new HtmlBuilder("ul");

            builder.AddChild("li", "Hello");
            builder.AddChild("li", "World");
            Console.WriteLine(builder.ToString());
            Console.WriteLine();

            Console.WriteLine("Fluent Builder with Recursive Generics:");
            Console.WriteLine();

            var person = RecursiveGenericsForFluentInheritance.Person.New
                         .Called("Peter Johnson")
                         .WorksAs("Journalist")
                         .Build();

            Console.WriteLine(person);

            Console.WriteLine();
            Console.WriteLine("Faceted Builder:");
            Console.WriteLine();

            var pb = new FacetedBuilder.PersonBuilder();

            FacetedBuilder.Person facetedPerson = pb.Works
                                                  .At("Toyota")
                                                  .AsA("Engineer")
                                                  .Earning(123000)
                                                  .Lives
                                                  .At("123 london Road")
                                                  .In("London")
                                                  .WithPostcode("ERD DFR");

            Console.WriteLine(facetedPerson);

            Console.ReadKey();
        }