|
-
Apr 6th, 2009, 02:25 PM
#1
Thread Starter
Frenzied Member
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);
}
}
}
-
Apr 6th, 2009, 02:30 PM
#2
Thread Starter
Frenzied Member
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);
}
}
}
-
Apr 6th, 2009, 02:31 PM
#3
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|