public static void Main() { ElementBuilder list = new ElementBuilder("li"); Console.WriteLine(list * 3); Console.WriteLine(); ElementBuilder div = new ElementBuilder("div"); div.AddAttribute("id", "page"); div.AddAttribute("class", "big"); div.AddContent("<p>Hello</p>"); Console.WriteLine(div * 2); Console.WriteLine(); string image = HTMLDispatcher.CreateImage("images/dog.png", "dog", "dog_img"); Console.WriteLine(image); string url = HTMLDispatcher.CreateURL("https://github.com", "GitHub-OOP-Projects", "C# OOP"); Console.WriteLine(url); string inputField = HTMLDispatcher.CreateInput("submit", "submitBtn", "Submit"); Console.WriteLine(inputField); }
//third method -> CreateInput() takes input type, name and value. public static string CreateInput(string inputType, string inputName, string inputValue) { ElementBuilder input = new ElementBuilder("input"); input.AddAttribute("type", inputType); input.AddAttribute("name", inputName); input.AddAttribute("value", inputValue); return(input.ToString()); }
//second method -> CreateURL() tekes url, title and text. public static string CreateURL(string url, string title, string text) { ElementBuilder urlObj = new ElementBuilder("a"); urlObj.AddAttribute("href", url); urlObj.AddAttribute("title", title); urlObj.AddContent(text); return(urlObj.ToString()); }
//Write a static class HTMLDispatcher that holds 3 static methods, //which takes a set of arguments and return the HTML element as string: //first method -> CreateImage() takes image source, alt and title. public static string CreateImage(string imageSource, string alt, string title) { ElementBuilder img = new ElementBuilder("img"); img.AddAttribute("src", imageSource); img.AddAttribute("alt", alt); img.AddAttribute("title", title); return(img.ToString()); }