实体类的属性转换成Dictionary
private static Dictionary<string, string> ConvertToDic(StationModel data) { Dictionary<string, string> dic = new Dictionary<string, string>(); foreach (PropertyInfo pro in typeof(StationModel).GetProperties()) { string value = pro.GetValue(data, null)?.ToString(); string name = pro.Name; if (string.IsNullOrEmpty(value)) continue; if (name == "Type") continue; dic.Add(name, value); } return dic; }
如果属性字段都是string类型就用Dictionary<string, string>,否则可以用Dictionary<string, object>

浙公网安备 33010602011771号