/// <summary> /// Checks value is greater /// </summary> public static IValidationCondition <TValue> IsGreater <TValue>( this IValidationCondition <TValue> condition, TValue comparable) where TValue : IComparable <TValue> { return(condition.Is(value => value.CompareTo(comparable) > 0)); }
/// <summary> /// Checks value is less or equal /// </summary> public static IValidationCondition <TValue> IsLessOrEqual <TValue>( this IValidationCondition <TValue> condition, TValue comparable) where TValue : IComparable <TValue> { return(condition.Is(value => value.CompareTo(comparable) <= 0)); }
/// <summary> /// Checks if value is match regex /// </summary> public static IValidationCondition <string> IsMatch( this IValidationCondition <string> condition, string regex, RegexOptions options = RegexOptions.None) { return(condition.Is(value => Regex.IsMatch(value, regex, options))); }
/// <summary> /// Checks value is in range (min: inclusive, max: exclusive) /// </summary> public static IValidationCondition <TValue> IsInRange <TValue>( this IValidationCondition <TValue> condition, TValue min, TValue max) where TValue : IComparable <TValue> { return(condition.Is(value => value.CompareTo(min) >= 0 && value.CompareTo(max) < 0)); }
/// <summary> /// Checks value is true /// </summary> public static IValidationCondition <bool> IsTrue( this IValidationCondition <bool> condition) { return(condition.Is(value => value)); }
/// <summary> /// Checks collection is contains /// </summary> public static IValidationCondition <ICollection <TElement> > IsContains <TElement>( this IValidationCondition <ICollection <TElement> > condition, TElement element) { return(condition.Is(value => value?.Contains(element) ?? false)); }
/// <summary> /// Checks enumerable has elements /// </summary> public static IValidationCondition <IEnumerable <TElement> > IsAny <TElement>( this IValidationCondition <IEnumerable <TElement> > condition) { return(condition.Is(value => value?.Any() ?? false)); }
/// <summary> /// Checks value is type of /// </summary> public static IValidationCondition <TValue> IsType <TValue>( this IValidationCondition <TValue> condition, Type type) { return(condition.Is(value => value?.GetType() == type)); }
/// <summary> /// Checks if value is valid email string /// </summary> public static IValidationCondition <string> IsEmail( this IValidationCondition <string> condition) { return(condition.Is(value => EmailAddress.IsValid(value))); }
public static IValidationCondition <string> IsNullOrWhitespace( this IValidationCondition <string> condition) { return(condition.Is(string.IsNullOrWhiteSpace)); }
/// <summary> /// Checks if value is whitespace /// </summary> public static IValidationCondition <string> IsWhitespace( this IValidationCondition <string> condition) { return(condition.Is(value => value?.All(x => char.IsWhiteSpace(x)) ?? false)); }
/// <summary> /// Checks if string has length /// </summary> public static IValidationCondition <string> HasLength( this IValidationCondition <string> condition, Func <int, bool> predicate) { return(condition.Is(value => value != null && predicate(value.Length))); }
public static IValidationCondition <string> IsEmpty( this IValidationCondition <string> condition, StringComparison stringComparison = StringComparison.InvariantCulture) { return(condition.Is(value => value.Equals(string.Empty, stringComparison))); }
/// <summary> /// Checks all elements suites for predicate /// </summary> public static IValidationCondition <IEnumerable <TElement> > IsAll <TElement>( this IValidationCondition <IEnumerable <TElement> > condition, Func <TElement, bool> predicate) { return(condition.Is(value => value?.All(predicate) ?? false)); }
/// <summary> /// Checks values has a value /// </summary> public static IValidationCondition <TValue> IsIn <TValue>( this IValidationCondition <TValue> condition, IEnumerable <TValue> values) { return(condition.Is(value => values.Contains(condition.Value))); }
/// <summary> /// Checks if value is valid url string /// </summary> public static IValidationCondition <string> IsUrl( this IValidationCondition <string> condition, UriKind kind = UriKind.Absolute) { return(condition.Is(value => Uri.TryCreate(condition.Value, kind, out _))); }
/// <summary> /// Checks values has a value /// </summary> public static IValidationCondition <TValue> IsIn <TValue>( this IValidationCondition <TValue> condition, params TValue[] values) { return(condition.Is(value => values.Contains(condition.Value))); }
/// <summary> /// Checks collection has count /// </summary> public static IValidationCondition <ICollection <TElement> > HasCount <TElement>( this IValidationCondition <ICollection <TElement> > condition, int count) { return(condition.Is(value => value?.Count == count)); }
/// <summary> /// Checks if value is valid /// </summary> public static IValidationCondition <TValue> Is <TValue>( this IValidationCondition <TValue> condition, Func <TValue, bool> predicate) { return(condition.Is(() => predicate(condition.Value))); }
/// <summary> /// Checks DateTime kind /// </summary> public static IValidationCondition <DateTime> IsDateTimeKind( this IValidationCondition <DateTime> validationCondition, DateTimeKind dateTimeKind) { return(validationCondition.Is(value => value.Kind == dateTimeKind)); }