Пример #1
0
        static IValidator <TModel> CreateValidator(
            Action <IValidationRule <TModel> > action)
        {
            var predicateGroups =
                new ValidationRulePredicateGroupsValidator <TModel>();
            var builder = new ValidationRuleBuilder <TModel>();
            var rule    = new ValidationRulePredicated <TModel>(builder, predicateGroups);

            action(rule);

            return(new ValidationRuleValidator <TModel>(builder));
        }
Пример #2
0
        public IValidationRulePredicated <TModel> When(
            IValidator <TModel> validator)
        {
            var predicateGroups
                = new ValidationRulePredicateGroupsValidator <TModel>(validator);

            var builder = new ValidationRuleBuilder <TModel>();
            var rule    = new ValidationRulePredicated <TModel>(
                builder, predicateGroups);

            _validators.Add(
                new ValidationRuleConditionalValidator <TModel>(
                    predicateGroups,
                    true, false,
                    builder)
                );

            return(rule);
        }
Пример #3
0
        public IValidationRulePredicated <TModel> Assert(
            IEnumerable <IValidationPredicate <TModel> > predicates)
        {
            var predicateGroups
                = new ValidationRulePredicateGroupsValidator <TModel>();

            predicateGroups.Add(predicates.ToArray());

            var builder = new ValidationRuleBuilder <TModel>();
            var rule    = new ValidationRulePredicated <TModel>(builder, predicateGroups);

            _validators.Add(
                new ValidationRuleConditionalValidator <TModel>(
                    predicateGroups,
                    true, true,
                    builder)
                );

            return(rule);
        }