当前位置: 首页>>代码示例>>C#>>正文


C# CSharpParser.ParseTypeMembers方法代码示例

本文整理汇总了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;
        }
开发者ID:modulexcite,项目名称:scriptcs-engine-mono,代码行数:59,代码来源:SyntaxParser.cs

示例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);
				}
			}
		}
开发者ID:mmooney,项目名称:MMDB.UITest,代码行数:19,代码来源:TargetControlGenerator.cs

示例3: ConvertMember

		string ConvertMember(string code)
		{
			CSharpParser parser = new CSharpParser();
			var expr = parser.ParseTypeMembers(code).Single();
			Assert.IsFalse(parser.HasErrors);
			return ConvertMember(expr);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:7,代码来源:CodeDomConvertVisitorTests.cs


注:本文中的ICSharpCode.NRefactory.CSharp.CSharpParser.ParseTypeMembers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。