I have the following HtmlLink:
HtmlLink htmlLink = new HtmlLink();
htmlLink.Attributes.Add("href", "/style/" + category + ".css");
htmlLink.Attributes.Add("type", "text/css");
htmlLink.Attributes.Add("rel", "stylesheet");
Im trying to write it in a one line statement, but I dont know the right syntax to write a statement like:
List<string> list = new List<string> { "one", "two", "three" };
Doing:
HtmlLink htmlLink = new HtmlLink() { ???? };
Can someone satisfy my curiosity?
As far as I can tell it can’t be done. You could always write an extension method:
Usage:
Not sure this has a great advantage over multiple adds though. Another option is to write a helper method somewhere that accepts a dictionary and spits out an HtmlLink with its attributes set.