示例#1
0
        public static IValidatedArgument <T> IsDefault <T>(this IArgument <T> argument, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (default(T) == null)
            {
                if (!ArgumentExtensions.ValidateIsNull(argument, message, out exception))
                {
                    throw exception;
                }
            }
            else
            {
                if (!ValidateIsDefault(argument.Value, argument.IsNegated, argument.ParameterName, message, out exception))
                {
                    throw exception;
                }
            }

            return(argument.AsValidatedArgument());
        }
        public static IValidatedArgument <Guid> IsEmpty(this IArgument <Guid> argument, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (!ValidateIsEmpty(argument.Value, argument.IsNegated, argument.ParameterName, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
        public static IValidatedArgument <Type> IsSubclassOf(this IArgument <Type> argument, Type otherValue, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (!ValidateIsSubclassOf(argument, otherValue, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
        public static IValidatedArgument <T> IsNull <T>(this IArgument <T> argument, string message = null) where T : class
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (!ValidateIsNull(argument, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
示例#5
0
        public static IValidatedArgument <string> IsNullOrWhitespace(this IArgument <string> argument, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (!ValidateIsNullOrWhitespace(argument, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
示例#6
0
        public static IValidatedArgument <T> Satisfies <T>(this IArgument <T> argument, bool value, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (!ValidateSatisfies(value, argument.IsNegated, argument.ParameterName, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
示例#7
0
        public static IValidatedArgument <T?> IsDefault <T>(this IArgument <T?> argument, string message = null) where T : struct
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (argument.Value.HasValue)
            {
                if (!ValidateIsDefault(argument.Value.Value, argument.IsNegated, argument.ParameterName, message, out exception))
                {
                    throw exception;
                }
            }

            return(argument.AsValidatedArgument());
        }
示例#8
0
        public static IValidatedArgument <IEnumerable <T> > IsEmpty <T>(this IArgument <IEnumerable <T> > argument, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            if (argument.Value == null)
            {
                throw new InvalidOperationException(Messages.ArgumentValueIsNull);
            }

            Exception exception;

            if (!ValidateIsEmpty(argument, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
示例#9
0
        public static IValidatedArgument <string> Contains(this IArgument <string> argument, string value, StringComparison comparisonType, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            if (argument.Value == null)
            {
                throw new InvalidOperationException(Messages.ArgumentValueIsNull);
            }

            Exception exception;

            if (!ValidateContainsWith(argument, value, comparisonType, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
        public static IValidatedArgument <T> IsDefined <T>(this IArgument <T> argument, string message = null) where T : struct, IConvertible
        {
            if (!typeof(T).IsEnum)
            {
                throw new InvalidOperationException(string.Format(Messages.GenericTypeParameterMustBeEnum, typeof(T).Name));
            }

            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            Exception exception;

            if (!ValidateIsDefined(argument.Value, argument.IsNegated, argument.ParameterName, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }
示例#11
0
        public static IValidatedArgument <ICollection <T> > Contains <T>(this IArgument <ICollection <T> > argument, T value, string message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(ParameterNames.Argument);
            }

            if (argument.Value == null)
            {
                throw new InvalidOperationException(Messages.ArgumentValueIsNull);
            }

            Exception exception;

            if (!ValidateContains(argument, value, message, out exception))
            {
                throw exception;
            }

            return(argument.AsValidatedArgument());
        }