I want to find all the method calls in one class which are made on another class.
For example:
If class1 calls class2.Foo() but not class2.Bar() then I want to know about it.
Almost like an analysis of coupling. Is this possible with reflection?
I want to find all the method calls in one class which are made on another class.
For example:
If class1 calls class2.Foo() but not class2.Bar() then I want to know about it.
Almost like an analysis of coupling. Is this possible with reflection?
This is possible, as it is done by several IDEs (at least for Java). In any case, you're likely to have a partially erreneous analysis. It is very difficult to determine at compile-time which methods are called in presence of method overrides in derived classes.
No, it is not possible with reflection. You need static code analysis to compute coupling metrics.
Nope, Reflection is all about types, not code. You can find out anything you want with System.Reflection about what a type looks like: fields, properties, events, methods. But method calls are encoded in IL. Reflection stops there, all you got is MethodInfo.GetMethodBody().
That didn't stop some people, you can actually interpret the IL handed to you by the method. Shining light there is Lutz Roeder and his awesome Reflector tool. Ninety percent of what I know about how the .NET framework actually works, and how I can advantage of it myself, was handed on a silver platter. Very awesome, give the guy a medal. And MSFT following up on that with the Reference Source.
you dont say if this is in code or as a utility. In code you would need to inspect the IL of a class.
For utilities you could try reflector or ncover (not sure if i have the correct name). Reflector has a plug in interface so you may be able to do something with that