0

for organizational purposes I'm setting the namespace in every class manually.
like if I have an project called myProject namespace is myProject I change it to mySolution.myProject then changing nested directories the same way

namespace myProject.Folder1
{
     ///
}

to

namespace mySolution.myProject.Folder1
{
     ///
}

this way multiple projects can be parts of one namespace,
Is this a valid way to do this?

Alaa Jabre
  • 1,843
  • 5
  • 26
  • 52

4 Answers4

1

Changing the namespace is perfectly fine. Sometimes it can be advantageous to do so. If you are importing a large project into a smaller project, it might just make sense to change the smaller project over to the namespace conventions of the larger project.

One gotcha when doing this relates to web mark up files. .aspx/.ascx, not sure about MVC markups. I recall having the issue in MVC2. Improper references to namespaces here will not get caught by the debug compiler and will throw an error when trying to load the page. So if you do change the namespace of existing files, remember to change other source files that aren't checked by the compiler as well.

Alexander Matusiak
  • 1,748
  • 2
  • 18
  • 29
0

Changing namespaces manually isn't a problem as long as you update any references to those namespaces.

ie in some other file you have;

using myProject.Folder1;

if that isn't updated to;

using mySolution.myProject.Folder1;

then you'll get compilation errors.

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
0

I would use Refactor's rename option for this, just to be sure there aren't any references to the incorrect namespace somewhere. As far as using mySolution.myProject as a namespace, I don't see anything wrong with it.

TOlsen
  • 45
  • 1
  • 2
  • 8
0

Changing the namespace from the default is pretty common. This stackoverflow question has a good answer about naming conventions:

namespace naming conventions.

Under your project properties, there is a setting on the Application tab where you can specify the default namespace. If you set that when you create your project, you won't have to manually change each class file as you create them.

Community
  • 1
  • 1