Exemple #1
0
        //Builder Example
        public static void Builder()
        {
            var hello = "hello";
            var sb    = new StringBuilder();

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

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

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

            // ^^ Old example of builder problem

            // vv New example of builder

            var builder = new Builder.HtmlBuilder("");

            builder.AddChild("li", "hello");
            builder.AddChild("li", "world");
            WriteLine(builder.ToString());
        }
Exemple #2
0
        //Fluent Builder Example
        public static void FluentBuilder()
        {
            var builder = new Builder.HtmlBuilder("");

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

            // ^^ Old example of builder

            // vv New example of Fluent builder

            var fluentbuilder = new FluentBuilder.HtmlBuilder("");

            fluentbuilder.AddChildFluent("li", "hello").AddChildFluent("li", "world");
            WriteLine(fluentbuilder.ToString());
        }