Пример #1
0
        public static void Main()
        {
            try
            {
                ElementBuilder div = new ElementBuilder("div");
                div.AddAttribute("id", "page");
                div.AddAttribute("class", "big");
                div.AddContent("<p>Hello</p>");

                Console.WriteLine(div);
                Console.WriteLine(div * 2);
                Console.WriteLine();

                string url = HTMLDispatcher.CreateURL("www.abv.bg", "Abv", "Link to abv.bg");
                string image = HTMLDispatcher.CreateImage("c://image.jpg", "some image", "Image");
                string input = HTMLDispatcher.CreateInput("text", "username", "user");

                Console.WriteLine(url);
                Console.WriteLine(image);
                Console.WriteLine(input);
                Console.WriteLine();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex);
            }          
        }
Пример #2
0
        public static void Main()
        {
            // Create anchor element
            var element = new ElementBuilder("a");
            element.AddAttribute("href", "www.softuni.bg");
            element.AddAttribute("class", "link");
            element.AddContent("Test Content");
            Console.WriteLine(element + Environment.NewLine);

            // Create and copy div element
            var div = new ElementBuilder("div");
            Console.WriteLine((div * 2) + Environment.NewLine);

            // Shorthand element creator
            Console.WriteLine(ElementBuilder.CreateImage("www.softuni.bg/logo.png", "SoftUni Logo", "SoftUni"));
            Console.WriteLine(ElementBuilder.CreateURL("www.softuni.bg", "SoftUni Website", "Learn how to write OOP in C# here!"));
            Console.WriteLine(ElementBuilder.CreateInput("input", "register", "Register") + Environment.NewLine);

            // Empty element test case
            // try
            // {
            //     new ElementBuilder("");
            // }
            // catch (ArgumentNullException e)
            // {
            //     Console.WriteLine(e);
            // }
        }
Пример #3
0
 public static string CreateImage(string source,string alt, string title)
 {
     var div = new ElementBuilder("img");
     div.AddAttribute("src",source);
     div.AddAttribute("alt", alt);
     div.AddAttribute("title", title);
     return div.ToString();
 }
Пример #4
0
        public static ElementBuilder CreateURL(string url = "", string title = "", string text = "")
        {
            var link = new ElementBuilder("a");
            link.AddAttribute("href", url);
            link.AddAttribute("title", title);
            link.AddContent(text);

            return link;
        }
Пример #5
0
        public static ElementBuilder CreateInput(string type = "", string name = "", string value = "")
        {
            var input = new ElementBuilder("input");
            input.AddAttribute("type", type);
            input.AddAttribute("name", name);
            input.AddAttribute("value", value);

            return input;
        }
Пример #6
0
        public static ElementBuilder CreateImage(string src = "", string alt = "", string title = "")
        {
            var image = new ElementBuilder("img");
            image.AddAttribute("src", src);
            image.AddAttribute("alt", alt);
            image.AddAttribute("title", title);

            return image;
        }