public static ArgumentEx <string> IsNotNullOrEmpty(this ArgumentEx <string> arg) { arg.IsNotNull(); arg.IsNotEmpty(); return(arg); }
public static ArgumentEx <string> FileDoesExistAtPath(this ArgumentEx <string> arg) { if (!File.Exists(arg.Value)) { throw new IOException("File does not exist at path: {0}".FormatWith(arg.Value)); } return(arg); }
public static ArgumentEx <string> StartsWith(this ArgumentEx <string> arg, string prefix) { if (!arg.Value.StartsWith(prefix)) { throw new ArgumentException("Parameter {0} must start with {1}.".FormatWith(arg.Name, prefix), arg.Name); } return(arg); }
public static ArgumentEx <byte> MeetsCriteria(this ArgumentEx <byte> x, Func <byte, bool> predicate) { if (predicate(x)) { return(x); } throw new ArgumentException("The argument {0} does not meet the required criteria.", x.Name); }
public static ArgumentEx <T> IsNotNull <T>(this ArgumentEx <T> arg) where T : class { if (arg.Value == null) { throw new ArgumentNullException(arg.Name); } return(arg); // for fluency }
public static ArgumentEx <string> IsNotEmpty(this ArgumentEx <string> arg) { if (arg == "") { throw new ArgumentException("The argument {0} may not be empty.".FormatWith(arg.Name), arg.Name); } return(arg); }
public static ArgumentEx <T> ExistsIn <T>(this ArgumentEx <T> arg, IEnumerable <T> list) { if (!list.Contains(arg.Value)) { throw new ArgumentException( "The argument {0} does not exist in the list provided.".FormatWith(arg.Name), arg.Name); } return(arg); }
public static ArgumentEx <byte> IsBetween( this ArgumentEx <byte> x, byte lowerBound, byte upperBound, bool inclusive = true) { if (!inclusive) { if (x > lowerBound && x < upperBound) { return(x); } } if (x >= lowerBound && x <= upperBound) { return(x); } throw new ArgumentException( "The argument {0} is not between {1} and {2}.".FormatWith(x.Name, lowerBound, upperBound)); }