Cleaning up 'using' directives
A suggestion arrived in email, and here is my response. (None of this is on the feature list for Whidbey, it’s just ideas.)
1. Fully qualify (all names / all names in namespace X / all instances of type Y / the instance under my cursor), removing a using directive if possible.
1a. Add 'global::' when doing this.
2. Least-qualify (one of the above) by removing namespace from the name and adding a using directive.
3. Partially-qualify names from stuff within this project. That means writing like this:
using System.Foo;
using System.Bar;
namespace Microsoft.Product.Feature.ComponentA
{
class C {}
}
namespace Microsoft.Product.Feature.ComponentB
{
class D
{
ComponentA.C x;
}
}
4. Find all unused using directives (one you can remove without changing the meaning of the code). A little tricky if you use #if, so avoid it.!
5. Sort using directives alphabetically. Insert a blank line to separate different top-level namespaces.