예제 #1
0
 public static Ensurable <T> Between <T>(this EnsurableArgument <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,
                                e => new ArgumentOutOfRangeException(ensurable.Name,
                                                                     exceptionMessage ?? string.Format("Value must be between {0} and {1} but was {2}.", lower, upper, ensurable))));
 }
예제 #2
0
 public static Ensurable <T?> NotNull <T>(this EnsurableArgument <T?> ensurable, string exceptionMessage = null) where T : struct
 {
     return(ensurable.Satisfies(x => x != null, e => new ArgumentNullException(ensurable.Name, exceptionMessage ?? "Cannot be null.")));
 }
예제 #3
0
 public static Ensurable <T> LessThanOrEqualTo <T>(this EnsurableArgument <T> ensurable, T other, string exceptionMessage = null) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(other) <= 0,
                                e => new ArgumentOutOfRangeException(ensurable.Name,
                                                                     exceptionMessage ?? string.Format("Value must be less than or equal to {0} but was {1}.", other, ensurable))));
 }
 public static Ensurable <T> GreaterThan <T>(this EnsurableArgument <T> ensurable, T other, string exceptionMessage = null) where T : IComparable <T>
 {
     return(ensurable.Satisfies(x => x.CompareTo(other) > 0,
                                e => new ArgumentOutOfRangeException(ensurable.Name,
                                                                     exceptionMessage ?? string.Format("Value must be greater than {0} but was {1}.", other, ensurable))));
 }