本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.CSharpParser.ParseTypeMembers方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpParser.ParseTypeMembers方法的具体用法?C# CSharpParser.ParseTypeMembers怎么用?C# CSharpParser.ParseTypeMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.CSharpParser
的用法示例。
在下文中一共展示了CSharpParser.ParseTypeMembers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public ParseResult Parse(string code)
{
var result = new ParseResult();
var parser = new CSharpParser();
var syntaxTree = parser.Parse(code);
var codeLines = code.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
var codeLinesDictionary = new Dictionary<int, Tuple<string, bool>>();
for (int i = 0; i < codeLines.Length; i++)
{
codeLinesDictionary.Add(i, new Tuple<string, bool>(codeLines[i], true));
}
var typeMembersTree = parser.ParseTypeMembers(code);
foreach (var typeMember in typeMembersTree.Where(x => x is TypeDeclaration || x is MethodDeclaration))
{
var element = typeMember.GetText();
if (typeMember is TypeDeclaration)
{
result.Declarations += element;
}
//else
//{
// result.Declarations += "public static partial ScriptCsMethod {";
// result.Declarations += element;
// result.Declarations += "}";
//}
for (var i = typeMember.StartLocation.Line - 1; i < typeMember.StartLocation.Line; i++)
{
var oldItem = codeLinesDictionary[i];
codeLinesDictionary[i] = new Tuple<string, bool>(oldItem.Item1, false);
}
}
var keysToRemove = codeLinesDictionary.Where(x => x.Value.Item2 == false).Select(i => i.Key);
keysToRemove.ToList().ForEach(x => codeLinesDictionary.Remove(x));
foreach (var correct in syntaxTree.Members)
{
var element = correct.GetText(); ;
result.Declarations += element;
}
if (syntaxTree.Errors.Any())
{
var evalLines = codeLines.Skip(syntaxTree.Errors.First().Region.BeginLine - 1).ToList();
result.Evaluations += string.Join(Environment.NewLine, evalLines);
//result.Evaluations = "public void ScriptCsInvoke() {" + Environment.NewLine;
//result.Evaluations = string.Join(Environment.NewLine, codeLinesDictionary.Select(i => i.Value.Item1));
//result.Evaluations += Environment.NewLine + "}";
}
var evaluationTree = parser.ParseStatements(result.Evaluations);
return result;
}
示例2: AddHyperLinkControl
public static void AddHyperLinkControl(TypeDeclaration classObject, TargetField field, string fullTypeName)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("[{0}(\"{1}\",\"{2}\")] ", typeof(UIClientPropertyAttribute).FullName, field.SourceFieldName, fullTypeName);
sb.AppendFormat("public Link {0}", field.SourceFieldName);
sb.AppendFormat("{{ get {{ return this.TryGetLink(\"ctrl00_{0}\"); }} }}", field.SourceFieldName);
using(StringReader reader = new StringReader(sb.ToString()))
{
CSharpParser parser = new CSharpParser();
var memberList = parser.ParseTypeMembers(reader);
foreach(var member in memberList)
{
var property = (PropertyDeclaration)member;
var role = new ICSharpCode.NRefactory.Role<ICSharpCode.NRefactory.CSharp.AttributedNode>("Member");
property.Remove();
classObject.AddChild(property, TypeDeclaration.MemberRole);
}
}
}
示例3: ConvertMember
string ConvertMember(string code)
{
CSharpParser parser = new CSharpParser();
var expr = parser.ParseTypeMembers(code).Single();
Assert.IsFalse(parser.HasErrors);
return ConvertMember(expr);
}