I am trying to create a VS extension, using Visual Studio Extensibility Essentials 2019. The extension needs to get the type of the selected item in a Visual Studio code file. I am able to get the text that was selected, but I would like to get the type of the selected item, so that I can use reflection to display more information.
[Command(PackageIds.MyCommand)]
internal sealed class MyCommand : BaseCommand<MyCommand>
{
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
{
var doc = await VS.Documents.GetActiveDocumentViewAsync();
var span = doc.TextView.Selection.SelectedSpans.FirstOrDefault();
var text = span.GetText();
await VS.MessageBox.ShowWarningAsync("MyCommand", text);
}
}
Any ideas, code samples, etc would be appreciated.