I suggest you ...

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:
[=>Folder root<=]
MyBigClass
[=>MyBigClassPartials<=]
MyBigClass_SetUp
MyBigClass_Update
MyBigClass_OtherStuff

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.

197 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    KabwlaKabwla shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    12 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Olivier J.Olivier J. commented  ·   ·  Flag as inappropriate

        I suggest that these non-namespace-relevant folders should look and behave like solution folders. The msdn article "How to: Organize a Solution Using Solution Folders" describes solution folders as:

        "Solution Folders are an organizational tool in Solution Explorer; corresponding Windows folders are not created."

      • evgenidbevgenidb commented  ·   ·  Flag as inappropriate

        One additional note:
        If you disable the namespace generation for particular folder, then all its subfolders shouldn't generate namespaces as well. Otherwise namespaces could get either confusing or buggy.

      • ADAD commented  ·   ·  Flag as inappropriate

        I voted for this because it is a good idea for library projects.

        I think a good way to realize it would be to append some settings to the Property-Window (F4) when a folder is selected in Solution-Explorer.

        There can be a new option called "Namespace-Alias". The value of this option will replace the folders namespace alias (not the whole namespace tree only that one node).

        There should be a way to define the whole namespace tree too and to ignore the folder node.

      • Denise del BandoDenise del Bando commented  ·   ·  Flag as inappropriate

        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.

      • Michael PatersonMichael Paterson commented  ·   ·  Flag as inappropriate

        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 MelgaardJens Melgaard commented  ·   ·  Flag as inappropriate

        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ásJuraj Juhás commented  ·   ·  Flag as inappropriate

        Yes, of course, the project folder properties (editable using Properties window) will be the best choice... .

      • Juraj JuhasJuraj Juhas commented  ·   ·  Flag as inappropriate

        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.).

      Feedback and Knowledge Base