/// <summary>
        ///   Retrieves the rules.
        /// </summary>
        /// <param name="action"> The action. </param>
        /// <returns> </returns>
        public static RuleList RetrieveRules(Action action)
        {
            RuleList rules = new RuleList();

            try
            {
                if (action == null)
                {
                    throw new ArgumentNullException("action");
                }

                RuleBuilderFactory actionRuleFactory   = new ActionRuleFactory();
                RuleBuilderFactory fieldRuleFactory    = new FieldRuleFactory();
                RuleBuilderFactory propertyRuleFactory = new PropertyRuleFactory();

                RuleBuilderDirector director = new RuleBuilderDirector();
                director.Builders.Add(new ActionObjectRuleBuilder(new ActionRuleSource(actionRuleFactory, action)));
                director.Builders.Add(new ActionPropertyRuleBuilder(new PropertyRuleSource(propertyRuleFactory, action)));
                director.Builders.Add(new ActionFieldRuleBuilder(new FieldRuleSource(fieldRuleFactory, action)));

                foreach (RuleBuilderBase builder in director.Builders)
                {
                    director.DefineBuilder(builder);
                    director.CreateRules();
                    rules.AddRange(director.RetrieveRules());
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(rules);
        }
Beispiel #2
0
 /// <summary>
 ///     Renders the rules.
 /// </summary>
 /// <param name="rules"> The rules. </param>
 /// <returns> </returns>
 public IValidationContext RenderRules(RuleList rules)
 {
     this.rules = rules;
     return(RenderRules());
 }