Skip to content

Instantly share code, notes, and snippets.

@SimplyChris
Created September 25, 2011 00:11
Show Gist options
  • Save SimplyChris/1240025 to your computer and use it in GitHub Desktop.
Save SimplyChris/1240025 to your computer and use it in GitHub Desktop.
Query String Helper Class
public class QueryStringHelper
{
private IDictionary _dictionary;
public int Count
{
get { return _dictionary.Count; }
}
public String HtmlStringValue
{
get { return GetHtmlStringValue(); }
}
public QueryStringHelper ()
{
_dictionary = new Dictionary<string,string>();
}
public void Add(string key, string value)
{
if (_dictionary.Contains(key))
{
throw new Exception(String.Format(("QueryStringHelper.Add: Key {0} already exists in the dictionary"), key));
}
_dictionary.Add(key, value);
}
private String GetHtmlStringValue ()
{
if (_dictionary.Count == 0)
return String.Empty;
var htmlString = String.Empty;
foreach (KeyValuePair<String, String> entry in (Dictionary<String, String>)_dictionary)
{
if (htmlString.Length == 0)
htmlString += "?";
else
htmlString += "&";
htmlString += String.Format("{0}={1}", entry.Key, entry.Value);
}
return htmlString;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment