/// <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;
        }
        /// <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);
        }
Example #3
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="RuleBuilderSource" /> class.
 /// </summary>
 /// <param name="factory"> The factory. </param>
 /// <param name="action"> The action. </param>
 protected RuleBuilderSource(RuleBuilderFactory factory, Action action)
 {
     if(factory == null)
     {
         throw new ArgumentNullException("factory");
     }
     if(action == null)
     {
         throw new ArgumentNullException("action");
     }
     this.factory = factory;
     this.action = action;
 }
Example #4
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="RuleBuilderSource" /> class.
 /// </summary>
 /// <param name="factory"> The factory. </param>
 /// <param name="action"> The action. </param>
 protected RuleBuilderSource(RuleBuilderFactory factory, Action action)
 {
     if (factory == null)
     {
         throw new ArgumentNullException("factory");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     this.factory = factory;
     this.action  = action;
 }