Easily maintain order in your directive blocks.
We software developers often fixate on odd bits and pieces of our craft. You don’t agree? Go out and try to convince a number of your colleagues that your current brace placement style should be altered. Didn’t get a fight there? What about how many white spaces should be used for indentation, and whether you should use tabs instead of plain spaces. Even better, how about a comment on the closing brace of a block noting what block is being closed, a la:
if (foo == bar)
{
Console.Write(“Foobar”);
} // end if foo==bar
Nicole Calinoiu’s fixation is the order of import/using statements in code files. As with any great developer, Calinoiu created a tool to ease the pain of the fixation. Calinoiu’s ImportSorter, an addin for Visual Studio 2005 works so well that Calinoiu was awarded Third Place in Larkware’s 2005 Programming Contest.
ImportSorter installs easily and adds a configuration option to Visual Studio’s Tools menu, plus a sort option to the context menu in supported code editor windows. The context menu’s sort option will fix up mangled orders even after Visual Studio has automatically added in a new directive or two. Imports and using statement sorting works for C#, J#, and VB.NET.
Calinoiu created a very flexible rule system for ImportsSorter. Sorting is controlled by groups of namespaces such as System, Microsoft, and user-specific namespaces. Both simple namespaces (System, e.g.) and compound namespaces (System.IO) can be listed, enabling great control over how the using/imports block is sorted. Blank lines can be injected between groups for better visual appearance.
Calinoiu’s very clear documentation doesn’t bother going into details on the rule configuration’s effect on sorting order, but rather lists example configurations and outputs. For example, in the project I’m currently working on, I use various Microsoft namespaces, NUnit, and namespaces specific to the solution I’m working on. The configuration shown in the following example results in the directive block displayed below the dialog.

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using nUGSoft.Entities;
using nUGSoft.Entities.Errors;
using nUGSoft.Entities.Validation;
Any number of configurations can be set, giving you exact control over how your using/imports directive block is formatted.
Calinoiu’s tool is another small, concise, handy widget which does its job really, really well.
