Make namespace configurable for folder
The namespace for new files created are automatically determined by the folder structure.
This often creates a problem if you wish to make a logical group of files (by placing them in a folder) that is not supposed to be a new namespace.
Creating the folder and moving the files is not a problem, but the trouble starts as soon as someone uses 'add class' on the folder.
Now the new file does not sit in the same namespace as the other files in the folder.
One example would be to use a folder to store partials of a big class:
it would be nice if I could assign [=>MyBigClassPartials<=] to the same namespace as the root,
So that new files end up in the correct namespace.
Bad Kitty commented
I have a related (but different) suggestion here:
Denise del Bando commented
i didnt realize it wasn't a visual studio feature till I merged my files with my coworker and he was seeing an error. (not sure why he got an error. I tried doing reverse, put back default value then delete the name space in my class & it was working.)
anyway, if i can upvote this many times i would. I think this should be a feature in VS and not from resharper.
I also suggested the same recently @ https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/4438154-visual-studio-add-namespace-property-to-project-f
Unfortunately I couldn't vote here, please vote my new suggestion too. Thank you.
Michael Paterson commented
Think of the App_Start folder that is popping up all over the place. Also, I like to keep extension method classes in an Extensions folder but would really like to have the namespace be the root namespace. Great idea.
Jens Melgaard commented
Although resharper adds this, ill vote for it here as ReSharper stores it in its files rather than in the project file, so we often experience it switching on and of...
Juraj Juhás commented
Yes, of course, the project folder properties (editable using Properties window) will be the best choice... .
Jan Kučera commented
This does not belong into the code. I would prefer to set it as a property of the folder, as suggested in https://connect.microsoft.com/VisualStudio/feedback/details/372405/allow-default-namespace-for-solution-folders
Juraj Juhas commented
I'm voting for this idea.
It can be nice to have property like "IsNamespaceProvider" on folders in C# (VB) projects.
If this property will be set to true (default value), than, if I add new class into this folder, folders's name will be automatically added to the class namespace (the same behavior as today). If the value of IsNamespaceProvider property will be false, than new class will be placed into the namespace of parent folder (or project namespace for the 1. level folder).
It can be usefull if I want to place classes to the same namespace, but, I want to place files into the separated folders. I can do it now, but, I have to always remember, that I need to remove folder name from the namespace in all files (.cs, .designer.cs, .xaml, etc.).