Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
internal static class QueryBuilder
{
internal static string Build(string uri, IDictionary<string, string> queryString)
{
var sb = new StringBuilder(uri);
var hasQuery = uri.IndexOf('?') != -1;
foreach (var item in queryString)
{
sb.Append(hasQuery ? '&' : '?');
sb.Append(item.Key);
sb.Append('=');
sb.Append(item.Value);
hasQuery = true;
}
return sb.ToString();
}
}
//usage
var url = QueryBuilder.Build(url, new Dictionary<string, string>
{
["query1"] = "Some value",
["query2"] = "Some value",
}),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment