コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public static Dictionary <string, string> ToDictionary(this IQueryString queryString)
        {
            TkDebug.AssertArgumentNull(queryString, nameof(queryString), null);

            return(queryString.ToDictionary(p => p.Key, p => p.Value));
        }
コード例 #4
0
 public static IQueryString Add(IQueryString collection)
 {
     return(new HttpQueryString(collection.ToDictionary()));
 }