Finding unused 'Imports' statements in VB.NET source code
The Visual Studio IDE allo开发者_C百科ws me to scan for unused references in VB.NET source code. But I also have a lot of unused Imports statements in my application.
Two questions:
- Is there a way to find unused
Imports
statements throughout my VB.NET source code? - Do unused
Imports
statements hurt the performance of my application?
It doesn't hurt runtime performance at all, the only time those using directives are actually used is at compile time.
The three reasons why you could want to keep your import count low are :
For clarity sake. Imports are a usefull way to learn at first glance what kind of operations a class is performing : don't waste this opportunity ! (eg if I see a Regex namespace imported on top of a file, I usually assume there's some regex work in it)
The more imports you have, the more likely you are to run into a name clash (ie having one type name refering to two different types in two different imported namespaces)
Since those directives are used at compile time, having lots of unused import could hurt buildtime and/or intelliSense performance. (Just speculating here, I don't know how IntelliSense is working behind the scenes)
If you want to get rid of those useless namespaces, I don't think there's any built-in support for that in Visual studio (I assume this is what you meant by "the VB.net IDE"), but you can either use some third party tools (eg Resharper) or some other IDEs (eg Eclipse.net)
I believe this inclusion is done at compile time, and only on demand.
In other words, no performance penalty.
First of all, unused / superfluous imports do not affect performance at all because of representing static, compile-time information only.
Second, tools like ReSharper exist to help you keep your code more maintainable, ease refactoring, clean-up obsolete stuff like unused imports etc.
精彩评论