/// <summary> /// 增加 RequiredAttribute 扩展方法 /// </summary> /// <param name="context"></param> /// <param name="columnName"></param> /// <param name="errorMessage"></param> /// <param name="allowEmptyStrings"></param> public static void AddRequiredAttribute(this DynamicObjectContext context, string columnName, string?errorMessage = null, bool allowEmptyStrings = false) { var parameters = new KeyValuePair <string, object?>[] { new(nameof(RequiredAttribute.ErrorMessage), errorMessage), new(nameof(RequiredAttribute.AllowEmptyStrings), allowEmptyStrings) }; context.AddMultipleParameterAttribute <RequiredAttribute>(columnName, parameters); }
/// <summary> /// 增加 DisplayAttribute 扩展方法 /// </summary> /// <param name="context"></param> /// <param name="columnName"></param> /// <param name="parameters"></param> public static void AddDisplayAttribute(this DynamicObjectContext context, string columnName, IEnumerable <KeyValuePair <string, object?> > parameters) => context.AddMultipleParameterAttribute <DisplayAttribute>(columnName, parameters);