Results 1 to 3 of 3

Thread: x:Light C# Concept test

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    x:Light C# Concept test

    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);
            }
        }
    }

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: x:Light C# Concept test

    Second Test:

    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);
            }
        }
    }

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: x:Light C# Concept test

    ...Comments still a bit funky and no class highlighting.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width