Determine variable type under caret in a Visual Studio macro

162 Views Asked by At

Is there a technique to determine the type under the cursor,ActiveDocument.Selection. I can use DTE.ExecuteCommand("Edit.GoToDefinition") to jump around the solution, and start parsing the file etc, but it seems a little kludgy.

I've tried using the FileCodeModel, but I cant get anything useful from it. I could be using it improperly though.

e.g:

void Foo()
{
 int i;
 SomeType st;

 i = 0;
 st = null;
}

If I placed the caret(or selection) on i, I'd like int as a result, if it was over st, I'd like SomeType, and if it was over the declaration of SomeType, again, I would like SomeType as an output.

Ideas?

1

There are 1 best solutions below

2
On

There is a way to find all references see How to implement find all reference? and you can test references found (it is not very efficient and can be time consuming). Hovever I did not managed to make code example working (may be it should run from extension?)