Take the 2-minute tour ×

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?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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.

share|improve this answer
I'd like to interfere in existing code and write addin which will produce something from my tags or something like that... Example: This will be in code: //BUG("Mike", "This is bug which Mike should fix") I'd like to analyze file, find this tag and fire procedure which match to this tag - create bug on TFS and assign it to Mike and add description (second argument) EnvDTE can be useful? Or should i find other libs to do that? –  Simon Jul 29 '11 at 10:15

NRefactory will do this for you:


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#.

share|improve this answer

If you'd like just to list method, class, property names, then Reflection is a good simple solution - e.g. see simple tutorial like Reflection/ListMethods.htm">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.

share|improve this answer
Assumptions: - i have access to source code, not only .dll - i'd like to analyze file and fire events, for example: run external tools, or generate some text and put it as a comment or something like that and all depending on defined tags. I don't want to decompile anything :) –  Simon Jul 29 '11 at 10:26
Thanks for the clarification - sorry I misunderstood! In that case it sounds like NRefactory is the thing for you. Commercially the editor from actipro also provides lots of parsing functionality too. –  Stuart Jul 29 '11 at 10:41

Your Answer


