Reputation: 602
So, my goal is to create a "view dependency" for my project APIs. Similar to how SQL Management Studio has "View dependency" for database objects which shows who are consuming these objects and to whom these objects depend on.
So if my NameSpace1.Class1.Method1 is consuming NameSpace2.Class1.Method2 then when I use "view dependency" for NameSpace1.Class1.Method1, NameSpace2.Class1.Method2 should be listed as a method on which NameSpace1.Class1.Method1 is dependent.
I know reflection and how it is/should be used to get the list of methods at the run-time and so forth. What I am looking for it a way to extract other methods which are being called from the method in question. Any pointer in this direction is appreciated.
Upvotes: 0
Views: 84
Reputation: 63264
If you carefully analyze ILSpy's code base, you might come across similar feature (usage analyzer),
https://github.com/icsharpcode/ILSpy
As this is an open source project, you can reuse its code following the open source licenses.
Upvotes: 0
Reputation: 100555
Get classes, that all properties/methods of each class/argument of each method - this way you get information for some of the dependencies using code that is already part of .Net Framework.
To get the rest you need to get IL of each method and see what is being called by starting with MethodBase.GetMethodBody. There are existing projects that allow to parse IL - i.e. see Traverse a c# method and anazlye the method body.
Upvotes: 1