コード例 #1
0
        public static ValidateTarget <TCollection> UntypedAll <TCollection>([ValidatedNotNull] this ValidateTarget <TCollection> target, Func <object, bool> predicate, Func <string> getErrorMessage = null)
            where TCollection : IEnumerable
        {
            bool passedPredicate = true;

            if (target.Value != null)
            {
                foreach (var item in target.Value)
                {
                    if (!predicate.Invoke(item))
                    {
                        passedPredicate = false;
                        break;
                    }
                }
            }

            if (!passedPredicate)
            {
                ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldAllBe(target));
            }

            return(target);
        }