Example #1
0
 public static Ensurable <T> NotEmpty <T>(this Ensurable <T> ensurable, Func <Ensurable <T>, Exception> exceptionFactory) where T : IEnumerable
 {
     return(ensurable.Satisfies(e => e.Cast <object>().Any(), exceptionFactory));
 }
Example #2
0
 public static Ensurable <T> In <T>(this Ensurable <T> ensurable, IEnumerable <T> collection, string exceptionMessage = null)
 {
     return(ensurable.Satisfies(collection.Contains, exceptionMessage ?? "Value was not contained in the specified collection."));
 }
 public static Ensurable <T> Between <T>(this Ensurable <T> ensurable, T lower, T upper,
                                         Func <Ensurable <T>, Exception> exceptionFactory) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(lower) > -1 && x.CompareTo(upper) < 1, exceptionFactory));
 }
 public static Ensurable <Type> HasAttribute <T>(this Ensurable <Type> ensurable,
                                                 Func <Ensurable <Type>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(x => x.GetCustomAttributes(typeof(T), true).Any(), exceptionFactory));
 }
 public static Ensurable <string> NotNullOrEmpty(this Ensurable <string> ensurable, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(s => !string.IsNullOrEmpty(s), exceptionFactory));
 }
Example #6
0
 public static Ensurable <string> DirectoryExists(this Ensurable <string> ensurable, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(Directory.Exists, exceptionFactory));
 }
 public static Ensurable <T> LessThanOrEqualTo <T>(this Ensurable <T> ensurable, T other, Func <Ensurable <T>, Exception> exceptionFactory) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(other) <= 0, exceptionFactory));
 }
 public static Ensurable <T> NotNull <T>(this Ensurable <T> ensurable, string exceptionMessage = null) where T : class
 {
     return(ensurable.Satisfies(x => x != null, exceptionMessage ?? "Cannot be null."));
 }
 public static Ensurable <string> DoesNotMatch(this Ensurable <string> ensurable, string regexPattern, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.DoesNotMatch(new Regex(regexPattern), exceptionFactory));
 }
 public static Ensurable <T> GreaterThanOrEqualTo <T>(this Ensurable <T> ensurable, T other, string exceptionMessage = null) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(other) >= 0,
                                exceptionMessage ?? string.Format("Value must be greater than or equal to {0} but was {1}.", other, ensurable)));
 }
 public static Ensurable <T?> NotNull <T>(this Ensurable <T?> ensurable, Func <Ensurable <T?>, Exception> exceptionFactory) where T : struct
 {
     return(ensurable.Satisfies(x => x != null, exceptionFactory));
 }
 public static Ensurable <T> GreaterThan <T>(this Ensurable <T> ensurable, T other, Func <Ensurable <T>, Exception> exceptionFactory) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(other) > 0, exceptionFactory));
 }
Example #13
0
 public static Ensurable <T> Not <T>(this Ensurable <T> ensurable, T other, string exceptionMessage = null)
 {
     return(ensurable.Satisfies(x => !EqualityComparer <T> .Default.Equals(ensurable, other),
                                exceptionMessage ?? string.Format("Cannot be {0}.", (T)ensurable)));
 }
Example #14
0
 public static Ensurable <T> Not <T>(this Ensurable <T> ensurable, T other, Func <Ensurable <T>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(x => !EqualityComparer <T> .Default.Equals(ensurable, other), exceptionFactory));
 }
 public static Ensurable <Type> IsAssignableTo(this Ensurable <Type> ensurable, Type assignableTo,
                                               Func <Ensurable <Type>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(x => assignableTo.IsAssignableFrom(ensurable), exceptionFactory));
 }
 public static Ensurable <string> DoesNotMatch(this Ensurable <string> ensurable, Regex regex, string exceptionMessage = null)
 {
     return(ensurable.Satisfies(s => !regex.IsMatch(ensurable),
                                exceptionMessage ?? string.Format("'{0}' does not match the required regex '{1}'.", ensurable, regex)));
 }
 public static Ensurable <Type> IsAssignableTo <T>(this Ensurable <Type> ensurable, string exceptionMessage = null)
 {
     return(ensurable.IsAssignableTo(typeof(T), exceptionMessage));
 }
 public static Ensurable <string> DoesNotMatch(this Ensurable <string> ensurable, Regex regex, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(s => !regex.IsMatch(ensurable), exceptionFactory));
 }
Example #19
0
 public static Ensurable <string> DirectoryExists(this Ensurable <string> ensurable, string exceptionMessage = null)
 {
     return(ensurable.Satisfies(Directory.Exists, exceptionMessage ?? string.Format("Directory '{0}' does not exist.", ensurable)));
 }
 public static Ensurable <string> Matches(this Ensurable <string> ensurable, string regexPattern, string exceptionMessage = null)
 {
     return(ensurable.Matches(new Regex(regexPattern), exceptionMessage));
 }
 public static Ensurable <T> LessThan <T>(this Ensurable <T> ensurable, T other, string exceptionMessage = null) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(other) < 0,
                                exceptionMessage ?? string.Format("Value must be less than {0} but was {1}.", other, ensurable)));
 }
 public static Ensurable <T> NotDefault <T>(this Ensurable <T> ensurable, Func <Ensurable <T>, Exception> exceptionFactory) where T : struct
 {
     return(ensurable.Satisfies(x => !EqualityComparer <T> .Default.Equals(ensurable, default(T)), exceptionFactory));
 }
 public static Ensurable <Type> HasAttribute <T>(this Ensurable <Type> ensurable, string exceptionMessage = null) where T : Attribute
 {
     return(ensurable.Satisfies(x => x.GetCustomAttributes(typeof(T), true).Any(),
                                exceptionMessage ?? string.Format("Type {0} does not have attribute {1}.", ensurable, typeof(T))));
 }
 public static Ensurable <T> NotDefault <T>(this Ensurable <T> ensurable, string exceptionMessage = null) where T : struct
 {
     return(ensurable.Satisfies(x => !EqualityComparer <T> .Default.Equals(ensurable, default(T)),
                                exceptionMessage ?? string.Format("Cannot have default value.")));
 }
 public static Ensurable <string> NotNullOrEmpty(this Ensurable <string> ensurable, string exceptionMessage = null)
 {
     return(ensurable.Satisfies(s => !string.IsNullOrEmpty(s), exceptionMessage ?? "Cannot be null or white space."));
 }
 public static Ensurable <Type> IsAssignableTo(this Ensurable <Type> ensurable, Type assignableTo,
                                               string exceptionMessage = null)
 {
     return(ensurable.Satisfies(x => assignableTo.IsAssignableFrom(ensurable),
                                exceptionMessage ?? string.Format("Type {0} is not assignable to type {1}.", ensurable, assignableTo)));
 }
Example #27
0
 public static Ensurable <T> In <T>(this Ensurable <T> ensurable, IEnumerable <T> collection, Func <Ensurable <T>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(collection.Contains, exceptionFactory));
 }
 public static Ensurable <Type> IsAssignableTo <T>(this Ensurable <Type> ensurable,
                                                   Func <Ensurable <Type>, Exception> exceptionFactory)
 {
     return(ensurable.IsAssignableTo(typeof(T), exceptionFactory));
 }
 public static Ensurable <T> Between <T>(this Ensurable <T> ensurable, T lower, T upper,
                                         string exceptionMessage = null) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(lower) > -1 && x.CompareTo(upper) < 1,
                                exceptionMessage ?? string.Format("Value must be between {0} and {1} but was {2}.", lower, upper, ensurable)));
 }
Example #30
0
 public static Ensurable <T> NotEmpty <T>(this Ensurable <T> ensurable, string exceptionMessage = null) where T : IEnumerable
 {
     return(ensurable.Satisfies(e => e.Cast <object>().Any(), exceptionMessage ?? "Collection must not be empty."));
 }