Created
October 9, 2012 02:12
-
-
Save radusuciu/3856183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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