Skip to content

Instantly share code, notes, and snippets.

@radusuciu
Created October 9, 2012 02:12
Show Gist options
  • Save radusuciu/3856183 to your computer and use it in GitHub Desktop.
Save radusuciu/3856183 to your computer and use it in GitHub Desktop.
public class QueryString {
Dictionary<string, string> parameters = new Dictionary<string, string>();
public QueryString Add<T>(string key, T value) {
parameters.Add(Uri.EscapeDataString(key), Uri.EscapeDataString(value.ToString()));
return this;
}
public QueryString Add<T>(Dictionary<string, T> p) {
foreach (var entry in p) {
Add(entry.Key, entry.Value);
}
return this;
}
public string Build() {
var queryString = new StringBuilder();
foreach (var entry in parameters) {
if (queryString.Length > 1) {
queryString.Append("&");
}
queryString.AppendFormat("{0}={1}", entry.Key, entry.Value);
}
return queryString.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment