예제 #1
0
        public static void Main(string[] args)
        {
            var builder = new HTMLBuilder("ul");

            builder.AddChild("li", "hello").AddChild("li", "world");
            Console.WriteLine(builder.ToString());
        }
예제 #2
0
        static void Main(string[] args)
        {
            //A builder for HTML elements
            //without 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);

            //with builder
            var builder = new HTMLBuilder("ul");

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