Created
August 9, 2021 14:30
-
-
Save deepumi/e3cff0113df7357caf805ce50b4a7fe6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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