Пример #1
0
        public static ValidateTarget <TCollection> CountNotInRange <TCollection>([ValidatedNotNull] this ValidateTarget <TCollection> target, int min, int max, Func <string> getErrorMessage = null)
            where TCollection : IEnumerable
        {
            bool isValidationFailed = true;

            int collectionCount = 0;

            if (target.Value == null)
            {
                isValidationFailed = false;
            }
            else
            {
                collectionCount = CollectionProxy <TCollection> .GetCount(target.Value);

                if (collectionCount < min || collectionCount > max)
                {
                    isValidationFailed = false;
                }
            }

            if (isValidationFailed)
            {
                ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldHaveCountInRange(target, min, max));
            }

            return(target);
        }
        public static ValidateTarget <TCollection> CountMaxByEnumeration <TCollection>([ValidatedNotNull] this ValidateTarget <TCollection> target, int valueToCompare, Func <string> getErrorMessage = null)
            where TCollection : IEnumerable
        {
            if (target.Value == null || CollectionProxy <TCollection> .GetCountByEnumeration(target.Value, valueToCompare + 1) > valueToCompare)
            {
                ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldHaveMaxCount(target, valueToCompare));
            }

            return(target);
        }
        public static ValidateTarget <TCollection> NotEmptyByEnumeration <TCollection>([ValidatedNotNull] this ValidateTarget <TCollection> target, Func <string> getErrorMessage = null)
            where TCollection : IEnumerable
        {
            if (target.Value != null && CollectionProxy <TCollection> .GetCountByEnumeration(target.Value, 1) == 0)
            {
                ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldNotBeEmpty(target));
            }

            return(target);
        }