示例#1
0
        /// <summary>
        /// Invokes all rule methods associated with
        /// the specified property.
        /// </summary>
        /// <param name="propertyName">The name of the property to validate.</param>
        public void CheckRules(string propertyName)
        {
            List <RuleMethod> list;

            // get the list of rules to check
            if (RulesList.ContainsKey(propertyName))
            {
                list = RulesList[propertyName];
                if (list == null)
                {
                    return;
                }

                // now check the rules
                foreach (RuleMethod rule in list)
                {
                    if (rule.Invoke())
                    {
                        BrokenRulesList.Remove(rule);
                    }
                    else
                    {
                        BrokenRulesList.Add(rule);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Given a list
        /// containing IRuleMethod objects, this
        /// method executes all those rule methods.
        /// </summary>
        private void CheckRules(List <IRuleMethod> list)
        {
            bool previousRuleBroken = false;
            bool shortCircuited     = false;

            for (int index = 0; index < list.Count; index++)
            {
                IRuleMethod rule = list[index];
                // see if short-circuiting should kick in
                if (!shortCircuited && (previousRuleBroken && rule.Priority > _processThroughPriority))
                {
                    shortCircuited = true;
                }

                if (shortCircuited)
                {
                    // we're short-circuited, so just remove
                    // all remaining broken rule entries
                    BrokenRulesList.Remove(rule);
                }
                else
                {
                    // we're not short-circuited, so check rule
                    if (rule.Invoke(_target))
                    {
                        // the rule is not broken
                        BrokenRulesList.Remove(rule);
                    }
                    else
                    {
                        // the rule is broken
                        BrokenRulesList.Add(rule);
                        if (rule.RuleArgs.Severity == RuleSeverity.Error)
                        {
                            previousRuleBroken = true;
                        }
                    }
                    if (rule.RuleArgs.StopProcessing)
                    {
                        shortCircuited = true;
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Invokes all rule methods for all properties
        /// in the object.
        /// </summary>
        public void CheckRules()
        {
            // get the rules for each rule name
            foreach (KeyValuePair <string, List <RuleMethod> > de in RulesList)
            {
                List <RuleMethod> list = de.Value;

                // now check the rules
                foreach (RuleMethod rule in list)
                {
                    if (rule.Invoke())
                    {
                        BrokenRulesList.Remove(rule);
                    }
                    else
                    {
                        BrokenRulesList.Add(rule);
                    }
                }
            }
        }