コード例 #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));
 }
コード例 #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."));
 }
コード例 #3
0
 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));
 }
コード例 #4
0
 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));
 }
コード例 #5
0
 public static Ensurable <string> NotNullOrEmpty(this Ensurable <string> ensurable, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(s => !string.IsNullOrEmpty(s), exceptionFactory));
 }
コード例 #6
0
 public static Ensurable <string> DirectoryExists(this Ensurable <string> ensurable, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(Directory.Exists, exceptionFactory));
 }
コード例 #7
0
 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));
 }
コード例 #8
0
 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."));
 }
コード例 #9
0
 public static Ensurable <string> DoesNotMatch(this Ensurable <string> ensurable, string regexPattern, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.DoesNotMatch(new Regex(regexPattern), exceptionFactory));
 }
コード例 #10
0
 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)));
 }
コード例 #11
0
 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));
 }
コード例 #12
0
 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));
 }
コード例 #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)));
 }
コード例 #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));
 }
コード例 #15
0
 public static Ensurable <Type> IsAssignableTo(this Ensurable <Type> ensurable, Type assignableTo,
                                               Func <Ensurable <Type>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(x => assignableTo.IsAssignableFrom(ensurable), exceptionFactory));
 }
コード例 #16
0
 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)));
 }
コード例 #17
0
 public static Ensurable <Type> IsAssignableTo <T>(this Ensurable <Type> ensurable, string exceptionMessage = null)
 {
     return(ensurable.IsAssignableTo(typeof(T), exceptionMessage));
 }
コード例 #18
0
 public static Ensurable <string> DoesNotMatch(this Ensurable <string> ensurable, Regex regex, Func <Ensurable <string>, Exception> exceptionFactory)
 {
     return(ensurable.Satisfies(s => !regex.IsMatch(ensurable), exceptionFactory));
 }
コード例 #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)));
 }
コード例 #20
0
 public static Ensurable <string> Matches(this Ensurable <string> ensurable, string regexPattern, string exceptionMessage = null)
 {
     return(ensurable.Matches(new Regex(regexPattern), exceptionMessage));
 }
コード例 #21
0
 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)));
 }
コード例 #22
0
 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));
 }
コード例 #23
0
 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))));
 }
コード例 #24
0
 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.")));
 }
コード例 #25
0
 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."));
 }
コード例 #26
0
 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)));
 }
コード例 #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));
 }
コード例 #28
0
 public static Ensurable <Type> IsAssignableTo <T>(this Ensurable <Type> ensurable,
                                                   Func <Ensurable <Type>, Exception> exceptionFactory)
 {
     return(ensurable.IsAssignableTo(typeof(T), exceptionFactory));
 }
コード例 #29
0
 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)));
 }
コード例 #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."));
 }