/// <summary> /// 键值对 /// </summary> public class Kv { /// <summary> /// 键 /// </summary> public string Key { get; set; } /// <summary> /// 值 /// </summary> public string Value { get; set; } }
List<Kv> kvs = new List<Kv>(); DataCircular circular = new DataCircular(); // 获取DataCircular实体的所有属性键和值 Type type = circular.GetType(); PropertyInfo[] properties = type.GetProperties(); foreach (PropertyInfo property in properties) { Kv _kv = new Kv(); _kv.Key = property.Name; if (property.GetValue(data) is double) { _kv.Value = ((float)Convert.ToDouble(property.GetValue(data))).ToString("f2"); } else { _kv.Value = property.GetValue(data).ToString(); } kvs.Add(_kv); }
标签:DataCircular,C#,GetValue,获取,键值,kv,new,property From: https://www.cnblogs.com/soulsjie/p/17427113.html