2

Is there a way to quickly "Auto qualify" a variable type declaration in Visual Studio 2013? E.g. if I type:

Dim SomeExcel as New Application

is there a way to get the IDE to automatically fill in the namespace? like this:

Dim SomeExcel as New Microsoft.Office.Interop.Excel.Application

The IDE seems to be able to infer the namespace readily enough; if I hover over the type name it can tell me what namespace(s) contain the type. Type namespace is identified by IDE


It would be really useful to me to be able to change an old project from "short names" like Application to fully qualified names like Microsoft.Office.Interop.Excel.Application without having to find each one and type out the whole namespace.

Or, in the event of an ambiguous name, if it would give me the option to pick which namespace and it would fill it in. Similar to how if you use an undefined class it will warn you and give you the options to either automatically add the Imports statement or even create a class stub for you.

Since it will do all that for you automatically, and it will make suggestions and autocomplete methods/properties for an interface instance as you type, I would be surprised if there was not a quick way to have it convert "short names" to fully qualified names, but if there is - I can't seem to find it! I looked through the menu commands, and various right-click menus, and I looked on MSDN but couldn't find anything - but i'm not sure I'm using the right search terms.
Hoping someone with more experience might know how to do this or if this functionality doesn't exist.

CBRF23
  • 1,340
  • 1
  • 16
  • 44
  • What if there is More than one Application classes available in two different namespace. ? How visual studio would know which one to include . – Garry Jul 10 '15 at 19:39
  • I would expect the IDE to tell me that, like it does now if I type an underqualified name - it warns me that it doesn't know which namespace it comes from and asks me to qualify it. But the majority of the time I'm able to hover over the type name and it shows me the fully qualified name, so I'm just wondering since it already knows it, can I get it to fill it in for me? – CBRF23 Jul 10 '15 at 19:42
  • The answer to your Question is NO there is no Way to make it fully qualified without selection from User.On hover Visual studio only know the path because it is already selected by you. – Garry Jul 10 '15 at 19:44
  • I don't really understand the downvotes on this question - anyone who downvoted it care to explain why? @Garry if you're sure there is no way, why not post that as an answer? – CBRF23 Jul 10 '15 at 19:50
  • 1
    I don't see why it's irrelevant - I'm asking if there is a way to do something in Visual Studio that seems like it would be a rational feature based on how intellitype works and the information available to the IDE - what is irrelevant about it? – CBRF23 Jul 10 '15 at 19:54
  • The community seems to have sided with you @Garry regarding this question, but I still don't see how it's irrelevant. The [Help article re: On-topic questions](http://stackoverflow.com/help/on-topic) says "software tools commonly used by programmers; " is a topic to be asked about on SO, and also further clarifies "Questions about general computing hardware and software are off-topic for Stack Overflow unless they directly involve tools used primarily for programming." I'm pretty sure Visual Studio is primarily used for programming... Would this be better on Super User or another site? – CBRF23 Jul 10 '15 at 20:01

1 Answers1

1

No, nothing exists in Visual Studio to do that.

Doing so also confers no special advantages, as VS will tell you if you have an ambiguous reference automatically and give you the possibilities to resolve it.

When that happens, just click the icon that appears when you hover over it and select the correct namespace. VS will then qualify it with that namespace.

Here's an image of the icon:

icon

And the resulting menu:

timer

Granted, that is for C#, but VB usually works the same way.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • that's exactly what I was expecting, but in my case it does *not* give me the option to click a namespace and fully qualify it. Is there a setting I am missing? Normally when I have a Compiler error, it gives a little red "X" icon which when hovered over provides options to fix it. I'm not getting that with ambigous names. I'm just getting the error, but then I have to manually type in the namespace details... – CBRF23 Jul 10 '15 at 21:05
  • You should see a blue underline on the left on hover, move towards that and click the square that appears. I'll try and get a screenshot – BradleyDotNET Jul 10 '15 at 21:08
  • Yeah, I'm not getting any square. Just like the screenshot above, if I hover it just shows me the error description - but no auto-fix options. – CBRF23 Jul 10 '15 at 21:09
  • Make sure to look for the *little* blue underline on hover, see my screenshots – BradleyDotNET Jul 10 '15 at 21:11
  • Yeah I definitely am not getting any icon at all, even hovering on line. Weird. I tried restarting VS, but still no change. Seems strange. – CBRF23 Jul 10 '15 at 21:12
  • I'm not aware of any way to turn those *off* so I don't know what to say, sorry :( – BradleyDotNET Jul 10 '15 at 21:13