HandCoded.Validation.RuleSet.Validate C# (CSharp) Method

Validate() protected method

Determines if the XmlDocument instance indexed by the provided NodeIndex has business data content that passes a validation test. If errors are detected they will be reported through the ValidationErrorHandler delegate passed as an argument.
Note that test returns true if it does not fail, including circumstances when the test is inapplicable to the XmlDocument under examination.
protected Validate ( NodeIndex nodeIndex, ValidationErrorHandler errorHandler ) : bool
nodeIndex HandCoded.Xml.NodeIndex The instance to examine.
errorHandler ValidationErrorHandler An delegate used to report /// validation failures.
return bool
        protected override bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result = true;
            Dictionary<Precondition,bool> cache = new Dictionary<Precondition, bool> ();

            foreach (Rule rule in rules.Values) {
                Precondition		condition = rule.Precondition;
                bool				applies;

                // Determine if the precondition has be evaluated before
                if (!cache.ContainsKey (condition)) {
                    applies = condition.Evaluate (nodeIndex, cache);
                    cache [condition] = applies;
                }
                else
                    applies = cache [condition];

                if (applies) result &= rule.PerformValidation (nodeIndex, errorHandler);
            }
            return (result);
        }

Usage Example

Exemplo n.º 1
0
 /// <summary>
 /// Uses the indicated <see cref="RuleSet"/> to perform a semantic validation of
 /// the <see cref="XmlDocument"/> and reports errors (if any). 
 /// </summary>
 /// <param name="document">The <see cref="XmlDocument"/> to be validated.</param>
 /// <param name="rules">The <see cref="RuleSet"/> to use.</param>
 /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param>
 /// <returns><b>true</b> if the <see cref="XmlDocument"/> successfully passed all
 /// applicable rules, <b>false</b> if one or more rules failed.</returns>
 public static bool Validate(XmlDocument document, RuleSet rules, ValidationErrorHandler errorHandler)
 {
     return (rules.Validate (document, errorHandler));
 }