Ejemplo n.º 1
0
        public static Param <string> HasLengthBetween(this Param <string> param, int minLength, int maxLength)
        {
            if (string.IsNullOrEmpty(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param, EnsureRes.Ensure_IsNotNullOrEmpty);
            }

            var length = param.Value.Length;

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

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

            return(param);
        }