反射 根据字段名获取字段值
////// 根据字段名称获取字段值 /// /// /// /// public static string GetModelValue(string fieldName, object obj) { try { Type ts = obj.GetType();
//字段名不区分大小写 object o = ts.GetProperty(fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase)?.GetValue(obj, null); string value = Convert.ToString(o); if (string.IsNullOrEmpty(value)) return null; return value; } catch { return null; } }