Example #1
0
        static void Main(string[] args)
        {
            //0. Without a Builder
            var hello = "hello";
            var sb    = new StringBuilder();

            sb.Append("<html><p>");
            sb.Append(hello);
            sb.Append("</p></html>");
            Console.WriteLine(sb);
            sb.Clear();

            var words = new[] { "hello", "world" };

            sb.Append("<html><ul>");
            foreach (var word in words)
            {
                sb.AppendFormat("<li>{0}</li>", word);
            }
            sb.Append("</ul></html>");
            Console.WriteLine(sb);

            //1. With an HTML Builder
            var pBuilder = new HTMLBuilder("");

            pBuilder.AddChild("p", "hello world");
            Console.WriteLine(pBuilder.ToString());

            var ulBuilder = new HTMLBuilder("ul");

            ulBuilder.AddChild("li", "hello").AddChild("li", "world");
            Console.WriteLine(ulBuilder.ToString());

            //2. Functional Builder
            var person = new PersonBuilder()
                         .Called("Lucas")
                         .WorkAs("Developer")
                         .Build();

            //3. Faceted Builder
            var employee = new EmployeeBuilder()
                           .Lives.At("Avenue O")
                           .In("Brooklyn")
                           .WithPostalCode("11333")
                           .Works.At("Lucasology")
                           .AsA("Developer")
                           .Earning(100000);
        }
Example #2
0
 public static PersonBuilder WorkAs
     (this PersonBuilder builder, string position)
 => builder.Do(p => p.Position = position);