using MAX.Core.Cryptography; using System.Collections.Generic; using System.Text; namespace MAX.Core.Extensions; public static class DictionaryExtension { /// /// 字典转url Get 参数 /// /// /// public static string ToUrlParams(this IDictionary parameters, bool IsUrlEncode = true) { IDictionary sortedParams = new SortedDictionary(parameters); IEnumerator> dem = sortedParams.GetEnumerator(); StringBuilder sb = new(""); while (dem.MoveNext()) { string key = dem.Current.Key; string value = dem.Current.Value; if (!string.IsNullOrEmpty(key)) { sb.Append(key).Append("=").Append(IsUrlEncode ? UrlHelper.Encode(value) : value).Append("&"); } } string content = sb.ToString().Substring(0, sb.Length - 1); return content; } }