public static Param <T?> IsNotNull <T>(this Param <T?> param) where T : struct
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param, ExceptionMessages.Common_IsNotNull_Failed);
            }

            return(param);
        }
Beispiel #2
0
        public static Param <string> IsNotNullOrEmpty(this Param <string> param)
        {
            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param, ExceptionMessages.Common_IsNotNull_Failed);
            }

            if (string.IsNullOrEmpty(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Strings_IsNotNullOrEmpty_Failed);
            }

            return(param);
        }
Beispiel #3
0
        public static Param <string> IsNotNullOrWhiteSpace(this Param <string> param)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param, ExceptionMessages.Common_IsNotNull_Failed);
            }

            if (string.IsNullOrWhiteSpace(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Strings_IsNotNullOrWhiteSpace_Failed);
            }

            return(param);
        }
        public static Param <T[]> HasItems <T>(this Param <T[]> param)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param, ExceptionMessages.Common_IsNotNull_Failed);
            }

            if (param.Value.Length < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_HasItemsFailed);
            }

            return(param);
        }
Beispiel #5
0
        public static Param <string> HasLengthBetween(this Param <string> param, int minLength, int maxLength)
        {
            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param, ExceptionMessages.Common_IsNotNull_Failed);
            }

            var length = param.Value.Length;

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

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

            return(param);
        }
        public static Param <Type> IsClass(this Param <Type> param)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param,
                                                                    ExceptionMessages.Types_IsClass_Failed_Null);
            }

            if (!param.Value.GetTypeInfo().IsClass)
            {
                throw ExceptionFactory.CreateForParamValidation(param,
                                                                ExceptionMessages.Types_IsClass_Failed.Inject(param.Value.FullName));
            }

            return(param);
        }