示例#1
0
 public static Func <T, ValidationResult> ValidateMax(T max, ValidationResult.Level level)
 {
     return((val) =>
     {
         if (val.CompareTo(max) > 0)
         {
             return new ValidationResult(level, string.Format("Must be no more than {0}", max));
         }
         return new ValidationResult();
     });
 }
示例#2
0
 public static Func <T, ValidationResult> ValidateMin(T min, ValidationResult.Level level)
 {
     return((val) =>
     {
         if (val.CompareTo(min) < 0)
         {
             return new ValidationResult(level, string.Format("Must be at least {0}", min));
         }
         return new ValidationResult();
     });
 }
示例#3
0
 public static Func <T, ValidationResult> ValidateMinMax(T min, T max, ValidationResult.Level level)
 {
     return((val) =>
     {
         var result = ValidateMin(min, level).Invoke(val);
         if (result.Severity == ValidationResult.Level.None)
         {
             result = ValidateMax(max, level).Invoke(val);
         }
         return result;
     });
 }
示例#4
0
 public static Func <string, ValidationResult> ValidateContains(Func <IList <Tuple <int, string, string> > > tupleF, ValidationResult.Level level)
 {
     return((val) => {
         var tuples = tupleF();
         foreach (var tuple in tuples)
         {
             if (tuple.Item2 == val)
             {
                 return new ValidationResult();
             }
         }
         return new ValidationResult(level, string.Format("Must be one of {0}", string.Join(", ", tuples.Select(tuple => tuple.Item2).ToArray())));
     });
 }