public static Param <bool> IsTrue(this Param <bool> param)
        {
            if (!param.Value)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotTrue);
            }

            return(param);
        }
Beispiel #2
0
        public static TypeParam IsOfType(this TypeParam param, Type type)
        {
            if (!param.Type.Equals(type))
            {
                throw ExceptionFactory.CreateForParamValidation(param,
                                                                ExceptionMessages.EnsureExtensions_IsNotOfType.Inject(param.Type.FullName));
            }

            return(param);
        }
Beispiel #3
0
        public static Param <T> IsGte <T>(this Param <T> param, T limit, Throws <T> .ExceptionFnConfig exceptionFn = null) where T : struct, IComparable <T>
        {
            if (param.Value.IsLt(limit))
            {
                if (exceptionFn != null)
                {
                    throw exceptionFn(Throws <T> .Instance)(param);
                }

                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotGte.Inject(param.Value, limit));
            }

            return(param);
        }
Beispiel #4
0
        public static Param <T> Is <T>(this Param <T> param, T expected, Throws <T> .ExceptionFnConfig exceptionFn = null) where T : struct, IComparable <T>
        {
            if (!param.Value.IsEq(expected))
            {
                if (exceptionFn != null)
                {
                    throw exceptionFn(Throws <T> .Instance)(param);
                }

                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_Is_Failed.Inject(param.Value, expected));
            }

            return(param);
        }
Beispiel #5
0
        public static Param <string> IsNotNullOrWhiteSpace(this Param <string> param, Throws <string> .ExceptionFnConfig exceptionFn = null)
        {
            if (string.IsNullOrWhiteSpace(param.Value))
            {
                if (exceptionFn != null)
                {
                    throw exceptionFn(Throws <string> .Instance)(param);
                }

                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotNullOrWhiteSpace);
            }

            return(param);
        }
Beispiel #6
0
        public static Param <string> HasLengthBetween(this Param <string> param, int minLength, int maxLength)
        {
            if (string.IsNullOrEmpty(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotNullOrEmpty);
            }

            var length = param.Value.Length;

            if (length < minLength)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToShort.Inject(minLength, maxLength, length));
            }

            if (length > maxLength)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToLong.Inject(minLength, maxLength, length));
            }

            return(param);
        }
Beispiel #7
0
        public static Param <Type> IsClass(this Param <Type> param)
        {
            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamValidation(param,
                                                                ExceptionMessages.EnsureExtensions_IsNotClass_WasNull);
            }

#if vNext || PCL
            if (!param.Value.GetTypeInfo().IsClass)
            {
                throw ExceptionFactory.CreateForParamValidation(param,
                                                                ExceptionMessages.EnsureExtensions_IsNotClass.Inject(param.Value.FullName));
            }
#else
            if (!param.Value.IsClass)
            {
                throw ExceptionFactory.CreateForParamValidation(param,
                                                                ExceptionMessages.EnsureExtensions_IsNotClass.Inject(param.Value.FullName));
            }
#endif
            return(param);
        }
Beispiel #8
0
        public static Param <T> IsInRange <T>(this Param <T> param, T min, T max, Throws <T> .ExceptionFnConfig exceptionFn = null) where T : struct, IComparable <T>
        {
            if (param.Value.IsLt(min))
            {
                if (exceptionFn != null)
                {
                    throw exceptionFn(Throws <T> .Instance)(param);
                }

                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToLow.Inject(param.Value, min));
            }

            if (param.Value.IsGt(max))
            {
                if (exceptionFn != null)
                {
                    throw exceptionFn(Throws <T> .Instance)(param);
                }

                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToHigh.Inject(param.Value, max));
            }

            return(param);
        }