Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for Intellisense to search for classes in unimported namespaces like in Eclipse?

In Eclipse, autocomplete works even for unused packages or namespaces. That means that if I have a class named DuckWrapper in a package, and in a class that didn't import the package DuckWrapper I press ctrl+space, it will display DuckWrapper and automatically import its package if necessary.

Visual Studio however, doesn't show it in its autocompletion unless I added it first to the using list.

Can that be changed?

like image 916
Uri Avatar asked Apr 22 '13 14:04

Uri


People also ask

How do I automatically add a namespace in Visual Studio?

To do it, you may either manually type the Using Namespace or you just right click on the class name and select Resolve > Namespace. But using “Ctrl+.” you can automatically add the namespace in your code.


2 Answers

This kind of feature exists in current version of Visual Studio 2019 but it is still experimental.

IntelliSense without this feature on

As you can see in the image above, you can't see the entity Student from the namespace Test2 that's in another project but if you click button in the bottom left corner of IntelliSense window, you will see this.

IntelliSense with this feature on

Upon accepting Student option that IntelliSense gives, all needed namespaces will automatically be added at the top of your file (or bellow all the existing using statements above the namespace name).

You can turn this option on/off in:

  • Tools
  • Options
  • Text Editor
  • C#
  • IntelliSense
  • Check/Uncheck the last option 'Show items from unimported namespaces (experimental)

EDIT: I embedded the images instead of just hyperlinking them.

like image 86
Dacha Avatar answered Sep 27 '22 18:09

Dacha


You may use the IntelliSense Extender Plugin. For Visual Studio 2017:

https://marketplace.visualstudio.com/items?itemName=Dreamescaper.IntelliSenseExtender

And for VS 2019:

https://marketplace.visualstudio.com/items?itemName=Dreamescaper.IntellisenseExtender2019

It includes the types of all projects in the solution and of all referenced packages. Selecting an not imported type from IntelliSense will then auto import that type.

like image 27
derMrich Avatar answered Sep 27 '22 16:09

derMrich