Exemplo n.º 1
0
 /// <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));
 }
Exemplo n.º 2
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));
 }
Exemplo n.º 3
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)));
 }
Exemplo n.º 4
0
 /// <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));
 }
Exemplo n.º 5
0
 /// <summary>
 ///   Checks value is true
 /// </summary>
 public static IValidationCondition <bool> IsTrue(
     this IValidationCondition <bool> condition)
 {
     return(condition.Is(value => value));
 }
Exemplo n.º 6
0
 /// <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));
 }
Exemplo n.º 7
0
 /// <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));
 }
Exemplo n.º 9
0
 /// <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)));
 }
Exemplo n.º 10
0
 public static IValidationCondition <string> IsNullOrWhitespace(
     this IValidationCondition <string> condition)
 {
     return(condition.Is(string.IsNullOrWhiteSpace));
 }
Exemplo n.º 11
0
 /// <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));
 }
Exemplo n.º 12
0
 /// <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)));
 }
Exemplo n.º 13
0
 public static IValidationCondition <string> IsEmpty(
     this IValidationCondition <string> condition,
     StringComparison stringComparison = StringComparison.InvariantCulture)
 {
     return(condition.Is(value => value.Equals(string.Empty, stringComparison)));
 }
Exemplo n.º 14
0
 /// <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)));
 }
Exemplo n.º 16
0
 /// <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)));
 }
Exemplo n.º 18
0
 /// <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)));
 }
Exemplo n.º 20
0
 /// <summary>
 ///   Checks DateTime kind
 /// </summary>
 public static IValidationCondition <DateTime> IsDateTimeKind(
     this IValidationCondition <DateTime> validationCondition,
     DateTimeKind dateTimeKind)
 {
     return(validationCondition.Is(value => value.Kind == dateTimeKind));
 }