开发者

Source code as objects in C# [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers. 开发者_开发知识库

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

Is there any way to represent class's source code as objects? I'd like to navigate through methods, theirs body etc. How tools like stylecop, ReSharper do it in Visual Studio 2010? Are there any external libraries which take as input source code file and produce representation of objects? Which i could read, modify or analyze?


As for already compiled assembly. Reflection can give you most info about object structure. But to get real code, you need to get down to IL.

As for code, that is open in Visual Studio, then VS exposes COM interface, that many of those plugins use. EnvDTE is managed wrapper around this interface. But documentation is scarce.


NRefactory will do this for you:

http://wiki.sharpdevelop.net/NRefactory.ashx

Edit: This is a "parser" which is what you want. It converts C# code into an abstract syntax tree which can then be modified with code and translated back to C#.


If you'd like just to list method, class, property names, then Reflection is a good simple solution - e.g. see simple tutorial like http://www.java2s.com/Tutorial/CSharp/0400__Reflection/ListMethods.htm

If you want more detailed analysis, including method bodies, then it might be a good idea to start from the source code from one or more of the Reflector replacements - e.g.

  • ILSpy - http://wiki.sharpdevelop.net/ILSpy.ashx
  • smooth reflector http://blog.smoothfriction.nl/archive/2011/02/07/building-your-own-reflector-with-mono-cecil-and-the-codedom.aspx
  • list here - Open Source Alternatives to Reflector?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜