I used the triplet class for the first time today! Yeeeeha! The triplet class is a little known class in the System.Web.UI namespace that is predominantly used for viewstate. Ever since I heard of it I've been dying to try it out. It served the purpose very well. It would be really cool if there was a typed dictionary version of the triplet but it works well enough as is so I can get by.
My purpose in using the triplet is in applying stylesheets to a page. I store a key to make sure the stylesheet doesn't get applied twice, the path to the stylesheet and the media property for the stylesheet.
The AddStyleSheet method looks like this (:
public void AddStylesheet(string key, string path, string media)
{
foreach (Triplet t in styleSheetList)
{
if (t.First.ToString().ToLower() == key) { return; }
}
styleSheetList.Add(new Triplet(key.ToLower(), path, media));
}
I would normally have opted to use a typed dictionary but I needed to store the media property as well. I use a dictionary for adding javascript files to the page like so:
public void AddJavascriptFile(string key, string scriptFile)
{
if (!javscriptFile.ContainsKey(key))
{
javscriptFile.Add(key, scriptFile);
}
}
This is a much more elegant solution since I don't need to iterate through the... (click here to read the rest)