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

岁酱吖の 提交于 2019-12-08 15:56:08

问题


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?


回答1:


This cannot be changed in a standard installation of Visual Studio, so you would need to install an extension to add the feature. One commonly used extension which provides this feature is JetBrain's ReSharper. Here is a quote from their documentation.

Import Symbol Completion (formerly Type Name Completion) is invoked with Ctrl+Alt+Space. Unlike Symbol Completion (which only completes types accessible at the current location), ReSharper displays all types that match a specified prefix regardless of what namespace they belong to, and automatically adds the appropriate namespace import directives when necessary. In C# code files, Import Symbol Completion works after dot with extension methods and puts necessary using directives.




回答2:


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.



来源:https://stackoverflow.com/questions/16149659/is-it-possible-for-intellisense-to-search-for-classes-in-unimported-namespaces-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!