using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SA.Core.Util { public class DictionaryHelper { public static string GetkvString(Dictionary keys) { StringBuilder str = new(); foreach (var item in keys) { str.Append(string.Format("{0}={1}", item.Key, item.Value)); str.Append("&"); } return str.ToString().TrimEnd('&'); } public static string GetJsonString(Dictionary keys) { StringBuilder str = new(); foreach (var item in keys) { str.Append(string.Format("\"{0}\":\"{1}\"", item.Key, item.Value)); str.Append(","); } return str.ToString().TrimEnd(','); } public static Dictionary GetKeyValues(T model ) { Dictionary keys = new(); if( model == null ) return keys; Type t= model.GetType(); var list = t.GetProperties().ToList(); foreach (var item in list) { var value = item.GetValue(model); if (value == null) value=""; keys.TryAdd(item.Name, value.ToString() ?? ""); } return keys; } } }