问题
In a VSpackage, is there a way to programmatically call, on a method, the "call hierarchy view" from code and access (even from code) to its results?
For completeness: VSpackage target is Visual Studio 2013.
Update
The final aim is to find how many times a given method (given its namespace and class) is used/called inside the opened solution.
回答1:
I'm going to say no. The reason is the "call hierarchy view" isn't going to expose it's data set directly. Instead you'd be better served going after the data set directly. You can use roslyn (the new C# compiler) to get this information. See: How to use C# to find usages of a class or method?
Alternatively, you could also use nrefactory to the same end. There is a tutorial on Code Project that shows how to use it: http://www.codeproject.com/Articles/408663/Using-NRefactory-for-analyzing-Csharp-code
Or if you just want to see how many times code is accessed in the IDE, you can upgrade to Visual Studio 2013 Ultimate and use Code Lens: http://blogs.msdn.com/b/zainnab/archive/2013/07/09/visual-studio-2013-preview-codelens-aka-code-information-indicators.aspx.
来源:https://stackoverflow.com/questions/26440055/visual-studio-call-hierarchy-view-call-it-programmatically