public static Argument <T> IsNotNull <T>(this Argument <T> argument) where T : class { if (argument.Value == null) { throw ExceptionFactory.CreateNullException(argument); } return(argument); }
public static Argument <T?> IsNotNull <T>(this Argument <T?> argument) where T : struct { if (argument.Value == null || !argument.Value.HasValue) { throw ExceptionFactory.CreateNullException(argument); } return(argument); }
public static Argument <string> IsNotNullOrEmpty(this Argument <string> argument) { if (argument.Value == null) { throw ExceptionFactory.CreateNullException(argument); } if (argument.Value.Length == 0) { throw ExceptionFactory.CreateArgumentException(argument, ExceptionMessages.Current.WasEmptyString); } return(argument); }
public static Argument <T> DoesNotContainNull <T>(this Argument <T> argument) where T : IEnumerable { if (argument.Value == null) { throw ExceptionFactory.CreateNullException(argument); } if (argument.Value.Cast <object>().Any(o => o == null)) { throw ExceptionFactory.CreateArgumentException(argument, ExceptionMessages.Current.ContainedNull); } return(argument); }
public static Argument <T> IsNotEmpty <T>(this Argument <T> argument) where T : IEnumerable { if (argument.Value == null) { throw ExceptionFactory.CreateNullException(argument); } if (!argument.Value.GetEnumerator().MoveNext()) { throw ExceptionFactory.CreateArgumentException(argument, ExceptionMessages.Current.EmptyCollection); } return(argument); }
private static Argument <T> IsGreaterThanOrEqualToImpl <T>(Argument <T> argument, object limit) { if (argument.Value == null) { throw ExceptionFactory.CreateNullException(argument); } if (argument.CompareValueTo(limit) < 0) { throw ExceptionFactory.OutOfRange( argument, ExceptionMessages.Current.NotGreaterThanOrEqualTo.Inject(limit, argument.Value)); } return(argument); }
public static Argument <Type> Is(this Argument <Type> argument, Type expectedType) { if (argument.Value == null) { throw ExceptionFactory.CreateNullException(argument); } if (!expectedType.IsAssignableFrom(argument.Value)) { throw ExceptionFactory.CreateArgumentException( argument, ExceptionMessages.Current.IsNotExpectedType.Inject(expectedType.FullName, argument.Value.FullName)); } return(argument); }
public static Argument <T> IsInRange <T>(this Argument <T> argument, T min, T max) where T : IComparable <T> { if (argument.Value == null) { throw ExceptionFactory.CreateNullException(argument); } if (argument.CompareValueTo(min) < 0) { throw ExceptionFactory.OutOfRange( argument, ExceptionMessages.Current.NotInRange_TooLow.Inject(min, max)); } if (argument.CompareValueTo(max) > 0) { throw ExceptionFactory.OutOfRange( argument, ExceptionMessages.Current.NotInRange_TooHigh.Inject(min, max)); } return(argument); }