views:

209

answers:

3

I want to automate the Visual Studio 2010 / Resharper 5 auto inserting import directives to put my internal namespaces into the namespace sphere. Like this:

using System;
using System.Collections.Generic;
using System.Linq;
using StructureMap;
using MyProject.Core;          // <--- Move inside.
using MyProject.Core.Common;   // <--- Move inside.

namespace MyProject.DependencyResolution
{
    using Core;
    using Core.Common;   // <--- My internal namespaces to be here!

    public class DependencyRegistrar
    {
        ...........
    }
}

Currently, I'm doing it manually, the problem is that with every refactoring the using directives going up, to the beginning of the page.

A: 

Saw this on another answer.

Kurt Johnson
This is not solving the problem, since is giving the option to move *all* the directives, and not just the project directives.
Mendy
A: 

I think readability is better served if the statements are either (all) outside the namespace declaration, or (all) inside of it.

Among the using statements, sorting them with the project statements last (as per your example code) is then preferred.

Resharper follows both the above conventions, so I would recommend sticking to those :)

Martin Aatmaa
I don't agree. I hope that will be a third option.
Mendy
+1  A: 

In R# 5.0:

ReSharper->Tools->Cleanup Code. Or simply press Ctrl+E, Ctrl+C.

Then use profile that has "Optimize 'using' directives" turned on.

Vadim

related questions