In .NET and Visual Studio projects, the convention is to let the physical directory structure of your project resemble the namespace structure of the project. I totally agree with that, and every time I work on a project that violates this guideline, I have trouble finding types, because it’s often unclear how to navigate the namespace hierarchy.
A problem I encounter however is that wrapping every class in a namespace is redundant, when using this guideline. Furthermore, it makes it very hard (without commercial refactoring tools) to restructure the project structure later on, because every file needs to be changed.
I believe that moving classes to a different namespace should simply be a drag ‘n drop of that file in another directory.
So how can we accomplish this? Is there a way to let the compiler (or any other tool) determine the namespace my classes (during compile time), based on the directory structure of my project?
Resharper can detect namespaces in code which do not match physical layout. Unfortunately Resharper is not cheap.
AFAIK the C# compiler has no knowledge of any relationship between namespace and physical location and therefore has no such options available.
IMHO this should be built into Visual Studio.