简体   繁体   中英

Can you add prefix to namespaces that ReSharper's “Adjust Namespaces” generates?

I'm working on a Unity/C# project where none of the files have namespaces. I like the idea of not having to manually add namespaces, and I like the idea of namespaces (somewhat) matching the folder structure. However, at the moment, using ReSharper's Adjust Namespaces causes namespaces of the type Game , Network , etc, which can obviously cause problems with other namespaces.

Is it possible to somehow tell ReSharper to use a prefix (eg "projectname.", "companyname.", "com.company.project.", etc) for the randomly generated prefixes? Or do we actually have to put all the files in anther folder just to get this structure (a bit like what you'd do in Java, I guess)?

ReSharper uses the project's default namespace as prefix to the folder names.

So maybe it's enough for you to set this default namespace to your desired prefix and use "Adjust Namespaces" again.

To set the default namespace:

  • right click on the project item in the project explorer
  • choose "Properties..."
  • on the project's property page, choose "Application" on the top left
  • set "Default namespace" to your desired prefix

In Unity projects you'll have to set the "root namespace" in the Unity projects settings (as OP pointed out himself):

Edit -> Project Settings -> Editor -> Root namespace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM