/// <summary> /// Builds the child rules for the given rule from the given XML node. /// </summary> /// <param name="parent">The rule to build the children for.</param> /// <param name="parentNode">The XML node containing the definition(s) /// of the chlid rules.</param> private void GetChildren( IValidationRule parent, XmlNode parentNode) { foreach (XmlNode ruleNode in parentNode) { string nodeName = ruleNode.Name; // null?? // if the rule has properties, set them on the rule object if (nodeName == "properties") { foreach (XmlNode paramNode in ruleNode.ChildNodes) { string attrName = StringUtilities.Capitalize(paramNode.Name); if (ReflectionUtilities.HasProperty(parent, attrName)) { ReflectionUtilities.SetPropertyValue(parent, attrName, paramNode.InnerText); } } // } else if (nodeName == "validator") { } else { IValidationRule rule = ValidationRuleFactory.Make(StringUtilities.Capitalize(nodeName)); if (rule != null) { if ((ruleNode.Attributes != null) && (ruleNode.Attributes.Count > 0)) { NameValueCollection attributes = new NameValueCollection(); foreach (XmlAttribute attr in ruleNode.Attributes) { attributes.Add(attr.Name, attr.Value); } ReflectionUtilities.Deserialize(rule, attributes); } //if (rule != null) { // // if there are any attributes on the rule node, try setting // // the corresponding property of the rule object // foreach (XmlAttribute attr in ruleNode.Attributes) { // string attrName = StringUtilities.Capitalize(attr.Name); // // this is really hokey, but it works for now // if ((attrName == "ErrorId") && ReflectionUtilities.HasProperty(rule, "ErrorId")) { // try { // // ReflectionUtilities.SetPropertyValue(rule, "ErrorId", long.Parse(attr.Value)); // ((BaseRule)rule).ErrorId = long.Parse(attr.Value); // } catch { // // TODO: log the failure? // } // } else if (ReflectionUtilities.HasProperty(rule, attrName)) { // ReflectionUtilities.SetPropertyValue(rule, attrName, attr.Value); // } // } // get the children of the rule GetChildren(rule, ruleNode); // add the rule to the parent's list of children parent.Add(rule); } // TODO: else log it? } } }