寻找一个C#代码解析器 [英] Looking for a C# code parser

查看:149
本文介绍了寻找一个C#代码解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一组课程(最好是在.net框架中),它将解析C#代码,并返回具有参数的函数列表,使用它们的方法,属性等的类。理想情况下,它将提供所需要的一切建立自己的智慧



我有一种这样的感觉,应该在.net框架中,给出他们提供的所有反思的东西,但如果不是那么一个开源的替代方案就够了。



我正在尝试构建的东西基本上是像Snippet Compiler一样,但是有一个扭曲。我试图找出如何获得代码dom第一。



我尝试谷歌搜索,但我不知道这是什么正确的术语是这样我没有空格。



编辑:由于我正在使用这种进行智能感知处理,实际编译代码将无法正常工作,因为它很可能是不完整的。对不起,我应该首先提到。

解决方案

虽然.NET的CodeDom命名空间提供了代码语言解析器的基本API ,它们没有被实现。 Visual Studio通过自己的语言服务来做到这一点。这些在可再分发框架中不可用。



您可以...


  1. 编译代码,然后在最终的程序集上使用反射。

  2. 查看创建这些语法树的Mono C#编译器。它不会像CodeDom这样的高级API,但也许你可以使用它。

可能有在CodePlex 或类似网站上的某些东西。



更新

看到这个相关的帖子。 C#的解析器


I'm looking for a set of classes (preferably in the .net framework) that will parse C# code and return a list of functions with parameters, classes with their methods, properties etc. Ideally it would provide all that's needed to build my own intellisense.

I have a feeling something like this should be in the .net framework, given all the reflection stuff they offer, but if not then an open source alternative is good enough.

What I'm trying to build is basically something like Snippet Compiler, but with a twist. I'm trying to figure out how to get the code dom first.

I tried googling for this but I'm not sure what the correct term for this is so I came up empty.

Edit: Since I'm looking to use this for intellisense-like processing, actually compiling the code won't work since it will most likely be incomplete. Sorry I should have mentioned that first.

解决方案

While .NET's CodeDom namespace provides the basic API for code language parsers, they are not implemented. Visual Studio does this through its own language services. These are not available in the redistributable framework.

You could either...

  1. Compile the code then use reflection on the resulting assembly
  2. Look at something like the Mono C# compiler which creates these syntax trees. It won't be a high-level API like CodeDom but maybe you can work with it.

There may be something on CodePlex or a similar site.

UPDATE
See this related post. Parser for C#

这篇关于寻找一个C#代码解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆