36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using MAX.Core.Cryptography;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Store.Framework.Extensions
|
|
{
|
|
public static class DictionaryExtension
|
|
{
|
|
/// <summary>
|
|
/// 字典转url Get 参数
|
|
/// </summary>
|
|
/// <param name="parameters"></param>
|
|
/// <returns></returns>
|
|
public static string ToUrlParams(this IDictionary<string, string> parameters, bool IsUrlEncode = true)
|
|
{
|
|
IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(parameters);
|
|
IEnumerator<KeyValuePair<string, string>> dem = sortedParams.GetEnumerator();
|
|
StringBuilder sb = new StringBuilder("");
|
|
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;
|
|
}
|
|
}
|
|
}
|