Given a string that represents a specific class/field/property (eg MyNameSpace.MyClass
or System.String.Length
), how can I programmatically cause Visual Studio to go to that class/field/property (ie, make Visual Studio do the same thing that would happen if I was to type in the reference in the code editor and then hit F12)?
You probably need to do the following.
IVsObjectManager2
interface (implemented by the SVsObjectManager
object)IVsObjectManager2.FindLibrary
to get the C# library, and cast the result to IVsSimpleLibrary2
.Call IVsSimpleLibrary2.GetList2
with the correct VSOBSEARCHCRITERIA2
in order to locate the symbol within the projects for your solution.
If the resulting IVsSimpleObjectList2
has GetItemCount()
==1
, and CanGoToSource
with VSOBJGOTOSRCTYPE.GS_DEFINITION
returns pfOK==true
, use the GoToSource
method to jump to the source.
Otherwise, rather than jumping to the source, simply display the possible options to the user. You will be able to use the IVsFindSymbol
interface (implemented by the SVsObjectSearch
object) to for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With