“CSharpCodeProvider.Parse”的替代方案是
我正在寻找 CSharpCodeProvider.Parse 的替代方案。该方法应该解析 [C#] 代码源并返回一个 CompileUnit
对象。但是,该方法并未在任何 .Net 框架中实现。
我的目的是能够导航 C# CodeDOM,而无需编译它。我正在编写一个进行一些代码分析的应用程序,但我不一定拥有所有外部引用,这意味着我无法编译它。
I'm looking for an alternative for CSharpCodeProvider.Parse
. The method was supposed to parse a [C#] code source and return a CompileUnit
object. However, the method isn't implemented in any .Net framework.
My purpose is to be able to navigate a C# CodeDOM without having to compile it. I'm writing a application that does some code analysis but I won't necessarily have all external references, which means I can't compile it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们的 DMS 软件再工程工具包是用于构建任意语言分析工具的工具。
DMS 提供广义解析、AST 导航和修改、从修改后的树重新生成源、符号表支持和各种分析支持,以及编写直接在表面上修改 AST 的源到源转换的能力句法。
它的 C# 前端 提供了一个完整的 C# 4.0 解析器(包括 LINQ),可以构建包含源文本的每个项目的完整抽象语法树,包括作为注释装饰的源树节点上捕获的注释。
Our DMS Software Reengineering Toolkit is a tool for building analysis tools for arbitrary languages.
DMS provides generalized parsing, AST navigation and modification, regeneration of source from a modified tree, symbol table support, and various kinds of analysis support as well as the ability to write source-to-source transformations that modify the ASTs directly in terms of surface syntax.
Its C# Front End provides a full C# 4.0 parser (including LINQ) that builds a full abstract syntax tree containing every item of the source text, including comments captured as annotations on source tree nodes that the comments decorate.
SharpDevelop(Mono 常用的开源 IDE)有一个名为 NRefactory 的库,它允许您解析 C# 代码并将其转换为 AST:http://wiki.sharpdevelop.net/NRefactory.ashx(该链接摘录如下):
SharpDevelop (the open source IDE commonly used for Mono) has a library called NRefactory that allows you to parse C# code and convert it into an AST: http://wiki.sharpdevelop.net/NRefactory.ashx (Excerpt from that link follows):
有许多免费 C# 解析器,最流行的显然是:
There are many free C# parsers, the most popular apparently being:
实际(2017-2018)信息:
更多信息请访问https://github.com /icsharpcode/SharpDevelop/wiki/NRefactory
下载 nuget 包:“ICSharpCode.NRefactory”
这里是代码片段:
Actual (2017-2018) info:
More info available at https://github.com/icsharpcode/SharpDevelop/wiki/NRefactory
Download nuget package: "ICSharpCode.NRefactory"
And here is code snippet: