예제 #1
0
        IRuleBuilderOptions <T, TProperty> IRuleBuilderOptions <T, TProperty> .DependentRules(Action action)
        {
            var dependencyContainer = new List <IValidationRuleInternal <T> >();

            // Capture any rules added to the parent validator inside this delegate.
            using (ParentValidator.Rules.Capture(dependencyContainer.Add)) {
                action();
            }

            if (Rule.RuleSets != null && Rule.RuleSets.Length > 0)
            {
                foreach (var dependentRule in dependencyContainer)
                {
                    if (dependentRule.RuleSets == null)
                    {
                        dependentRule.RuleSets = Rule.RuleSets;
                    }
                }
            }

            Rule.AddDependentRules(dependencyContainer);
            return(this);
        }