public string GenerateUrl(TUrlParams urlParams, IQueryString queryString = null) { string url = $"{this.BaseUrl.TrimEnd('/')}/{this.Path.TrimStart('/')}"; if (urlParams != null) { foreach (var urlParam in urlParams.UrlParamsDictionary) { url = UrlHelper.ReplaceOrRemove(url, urlParam.Key, urlParam.Value); } } url = UrlHelper.ClearTags(url); if (queryString != null) { var queryStringDictionary = new Dictionary <string, string>(); foreach (var parameter in queryString.ToDictionary()) { if (!string.IsNullOrEmpty(parameter.Key) && parameter.Value != null && !string.IsNullOrEmpty(parameter.Value.ToString())) { queryStringDictionary.Add(parameter.Key, parameter.Value.ToString()); } } if (queryStringDictionary.Any()) { url += $"?{string.Join("&", queryStringDictionary.Select(x => $"{x.Key}={x.Value}"))}"; } } return(url); }
public IQueryString Add(IQueryString collection) { IQueryString queryString = this; var dictionary = collection.ToDictionary(); foreach (var pair in dictionary) { queryString = this.Add(pair.Key, pair.Value); } return(queryString); }
public static Dictionary <string, string> ToDictionary(this IQueryString queryString) { TkDebug.AssertArgumentNull(queryString, nameof(queryString), null); return(queryString.ToDictionary(p => p.Key, p => p.Value)); }
public static IQueryString Add(IQueryString collection) { return(new HttpQueryString(collection.ToDictionary())); }