Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically inspect .NET code

I am looking for a way to programmatically inspect a .NET (C#, VB.NET,..) source code to perform static code analysis.

I'd like to perform queries on the code such as: - list classes whose name begin by x - list all the subclasses of x - list methods which instanciate an object of class x - determine if method x contains a variable named y - list methods calling the method y - ...

What I am looking for is an API or something else allowing me to write programs able to examine a source code.

like image 927
Monkeyget Avatar asked Oct 26 '09 09:10

Monkeyget


2 Answers

NDepend gives a SQL-like query language for querying .NET code structure.

like image 110
stusmith Avatar answered Nov 15 '22 06:11

stusmith


You can use System.Reflection, that should do the trick nicely for some of the things you want. As far as getting into the IL itself, check out Mono's Cecil.

like image 41
MichaelGG Avatar answered Nov 15 '22 08:11

MichaelGG