public static IEnumerable <Rule> Load(TextReader reader) { var doc = XDocument.Load(reader); foreach (var ruleNode in doc.Element("rules").Elements("rule")) { var rule = new Rule { RuleChecker = BizRulezChecker.RuleCheckers.FromCheckerId(ruleNode.Element("checkerId").Value), ObjectTypeId = ruleNode.Element("objectTypeId").Value, ViewName = ruleNode.Element("viewName").Value, Key = ruleNode.Element("key").Value, TechnicalComment = ruleNode.Element("technicalComment").Value, ErrorInfoTemplate = ruleNode.Element("errorInfoTemplate").Value, Parameters = new RuleParameterSet( from paramNode in ruleNode.Element("parameters").Elements("parameter") select RuleParameterSet.CreateParameter( paramNode.Attribute("typeId").Value, paramNode.Attribute("name").Value, paramNode.Value)) }; if (rule.RuleChecker == null) { throw new InvalidRuleCheckerException(String.Format("Unknown rule checker id {0} found", ruleNode.Element("checkerId").Value)); } var contextAttribute = ruleNode.Attribute("context"); if (contextAttribute != null) { rule.Contexts = new List <string> { contextAttribute.Value }; } else { var contexts = ruleNode.Element("contexts"); if (contexts != null) { rule.Contexts = new List <string>( from contextNode in contexts.Elements("context") select contextNode.Value); } } var affectedFieldNames = ruleNode.Element("affectedFieldNames"); if (affectedFieldNames != null) { rule.AffectedFieldNames = new List <string>( from fieldNameNode in affectedFieldNames.Elements("fieldName") select fieldNameNode.Value); } yield return(rule); } }