Skip to content

Instantly share code, notes, and snippets.

@deepumi
Created August 9, 2021 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepumi/e3cff0113df7357caf805ce50b4a7fe6 to your computer and use it in GitHub Desktop.
Save deepumi/e3cff0113df7357caf805ce50b4a7fe6 to your computer and use it in GitHub Desktop.
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