Source code as objects in C #

Is there a way to present the source code of a class as objects? I would like to navigate through methods, their body, etc. How do tools like stylecop, ReSharper do it in Visual Studio 2010? Are there any external libraries that take source code and create a representation of objects as a source file? What could I read, modify or analyze?

+4
source share
3 answers

As for an already compiled assembly. Reflection can give you more information about the structure of an object. But to get the real code, you need to go to IL .

As for the code that is open in Visual Studio, VS provides a COM interface that many of these plugins use. EnvDTE is controlled by a wrapper around this interface. But the documentation is not enough.

+2
source

NRefactory will do it for you:

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

Edit: this is the "parser" you want. It converts C # code into an abstract syntax tree, which can then be modified using code and translated back to C #.

+2
source

If you just want to list the names of methods, classes, properties, then Reflection is a good simple solution - for example. see a simple tutorial like http://www.java2s.com/Tutorial/CSharp/0400__Reflection/ListMethods.htm

If you need a more detailed analysis, including method bodies, then it might be a good idea to start with the source code from one or more Reflector replacements - for example,

0
source

All Articles