/// <summary> /// 实体中的字符串去掉前后空格 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> public static void Trim<T>(this T model, BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance) where T : class { if (model is null) { return; } var stringProperties = typeof(T).GetProperties(bindingAttr).Where(p => p.PropertyType == typeof(string)); foreach (var strProp in stringProperties) { string value = strProp.GetValue(model)?.ToString().Trim() ?? string.Empty; strProp.SetValue(model, value); } }