/// <summary> /// 要求必须输入 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <param name="errorMessage">错误提示消息</param> /// <returns></returns> public static FluentApi <T> Required <T, TKey>(this FluentApi <T> fluent, Expression <Func <T, TKey> > keySelector, string errorMessage) { return(fluent.SetRule(keySelector, new RequiredAttribute { ErrorMessage = errorMessage })); }
/// <summary> /// 验证是邮箱格式 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <returns></returns> public static FluentApi <T> Email <T>(this FluentApi <T> fluent, Expression <Func <T, string> > keySelector) { return(fluent.SetRule(keySelector, new EmailAttribute())); }
/// <summary> /// 表示验值要在一定的区间中 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <param name="minValue">最小值</param> /// <param name="maxValue">最大值</param> /// <returns></returns> public static FluentApi <T> Range <T, TKey>(this FluentApi <T> fluent, Expression <Func <T, TKey> > keySelector, double minValue, double maxValue) { return(fluent.SetRule(keySelector, new RangeAttribute(minValue, maxValue))); }
/// <summary> /// 要求必须输入 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <returns></returns> public static FluentApi <T> Required <T, TKey>(this FluentApi <T> fluent, Expression <Func <T, TKey> > keySelector) { return(fluent.SetRule(keySelector, new RequiredAttribute())); }
/// <summary> /// 表示精度验证 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <param name="min">最小精度</param> /// <param name="max">最大精度</param> /// <returns></returns> public static FluentApi <T> Precision <T, TKey>(this FluentApi <T> fluent, Expression <Func <T, TKey> > keySelector, int min, int max) { return(fluent.SetRule(keySelector, new PrecisionAttribute(min, max))); }
/// <summary> /// 表示验证不要和正则表达式匹配 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <param name="pattern">正则表达式</param> /// <returns></returns> public static FluentApi <T> NotMatch <T>(this FluentApi <T> fluent, Expression <Func <T, string> > keySelector, string pattern) { return(fluent.SetRule(keySelector, new NotMatchAttribute(pattern))); }
/// <summary> /// 验证不要和目标属性的值一致 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TTargetKey"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <param name="targetKeySelector">目标属性选择</param> /// <returns></returns> public static FluentApi <T> NotEqualTo <T, TKey, TTargetKey>(this FluentApi <T> fluent, Expression <Func <T, TKey> > keySelector, Expression <Func <T, TTargetKey> > targetKeySelector) { var propertyName = FluentApiExtend.GetProperty(targetKeySelector).Name; return(fluent.SetRule(keySelector, new NotEqualToAttribute(propertyName))); }
/// <summary> /// 验证输入的长度范围 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <param name="maxLength">最大长度</param> /// <returns></returns> public static FluentApi <T> Length <T>(this FluentApi <T> fluent, Expression <Func <T, string> > keySelector, int maxLength) { return(fluent.SetRule(keySelector, new LengthAttribute(maxLength))); }
/// <summary> /// 验证是邮箱格式 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fluent"></param> /// <param name="keySelector">属性选择</param> /// <param name="errorMessage">错误提示消息</param> /// <returns></returns> public static FluentApi <T> Email <T>(this FluentApi <T> fluent, Expression <Func <T, string> > keySelector, string errorMessage) { return(fluent.SetRule(keySelector, new EmailAttribute { ErrorMessage = errorMessage })); }