This is the first concept for the new c# highlighting feature of x:Light...
Code:using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using System.Text; using System.Text.RegularExpressions; namespace xLight { class ExpressionRule { private List<SubRule> mListOfSubRules = new List<SubRule>(); public List<SubRule> ListOfSubRules { get { return mListOfSubRules; } } private Regex mMasterExpression; public String MasterExpression { get { return mMasterExpression.ToString(); } private set { mMasterExpression = new Regex(value); } } public ExpressionRule(String SourceType, String OutputType) { PopulateList(SourceType.ToUpper(), OutputType.ToUpper()); CreateMasterExpression(); } private void PopulateList(String SourceType, String OutputType) { //Populate The ListOfSubRules Property using LINQ to XML var XMLSubRules = from XMLSubRule in XDocument.Load("DataStore.xml").Descendants("SubRule") where (XMLSubRule.Attribute("SourceType").Value == SourceType && XMLSubRule.Attribute("OutputType").Value == OutputType) select new { Expression = XMLSubRule.Element("Expression").Value, IsMatchExpression = XMLSubRule.Element("IsMatchExpression").Value, OpeningElement = XMLSubRule.Element("OpeningElement").Value, ClosingElement = XMLSubRule.Element("ClosingElement").Value }; foreach (var XMLSubRule in XMLSubRules) { ListOfSubRules.Add(new SubRule(XMLSubRule.Expression, XMLSubRule.IsMatchExpression, XMLSubRule.OpeningElement, XMLSubRule.ClosingElement)); } } private void CreateMasterExpression() { String RawMasterExpressionString = String.Empty; foreach (SubRule SubRuleItem in ListOfSubRules) { const string AndOrSymbol = "|"; RawMasterExpressionString = RawMasterExpressionString + AndOrSymbol + SubRuleItem.Expression; } // Removes the first OR from the string otherwise it will error. MasterExpression = RawMasterExpressionString.Remove(0,1); } } }




Reply With Quote