public static OptionalMessagePropertyValidationContext <string> Matches( this PropertyValidationContextBase <string> context, string pattern) { var regex = new Regex(pattern); return(context.BeginPredicate( v => v == null || regex.IsMatch(v), () => $"{context._currentRuleset.PropExpr.GetPropertyName()} is not valid." )); }
public static OptionalMessagePropertyValidationContext <T> GreaterThan <T>( this PropertyValidationContextBase <T> context, T lowerBound, Comparer <T> comparer = null) where T : IComparable <T>, IComparable { comparer = DefaultIfNull(comparer); var name = context.PropertyName; return(context.BeginPredicate( x => comparer.Compare(x, lowerBound) > 0, () => $"{name} must be greater than {lowerBound}")); }
public static OptionalMessagePropertyValidationContext <T> LessThanOrEqualTo <T>( this PropertyValidationContextBase <T> context, T upperBound, Comparer <T> comparer = null) where T : IComparable <T>, IComparable { comparer = DefaultIfNull(comparer); var name = context.PropertyName; return(context.BeginPredicate( x => comparer.Compare(x, upperBound) > 0, () => $"{name} must be no more than {upperBound}")); }