简体   繁体   中英

ReSharper Adjust/Refactor Namespaces not respecting folders with spaces in them

I'm trying to refactor the namespaces in my project with ReSharper 8.2. I'm using the Refactor->Adjust Namespaces option, which is really awesome, but it doesn't seem to work when the folders in the project have spaces. With this project structure (in VS):

Project
   |
   |-Some Folder
       |
       |-ASubFolder
          |
          |-CodeFile.cs

My new namespace in CodeFile.cs will be Project.ASubFolder , whereas if I have this structure

Project
   |
   |-SomeFolder
       |
       |-ASubFolder
          |
          |-CodeFile.cs

The namespace is renamed appropriately to Project.SomeFolder.ASubFolder . I have checked that the Namespace provider property is set on all the folders. How do I force R# to use folders with spaces in them when refactoring?

Edit: My expected output in the first scenario is Project.SomeFolder.ASubFolder . I want ReSharper to just remove the space.

You can't have spaces in a namespace (ie Project.Some Folder.ASubFolder would not be valid).

So whatever ReSharper did in this situation (such as ignoring the spaces), you'd end up with a mismatch between your folder structure and your namespaces. Ignoring the folder name completely if it contains spaces seems as reasonable as any other solution.

Having spaces in folder names is just going to cause you problems with other tools in future so is best avoided if you can.

The work-around my team ended up using for this problem was to replace spaces in the folder names with underscores.

Because the Visual Studio convention is to use underscores in namespaces where spaces exist in folders, any class which was already using the correct namespace would not have to change. Because the spaces were gone, we were free to run ReSharper's Fix Namespaces to achieve the same result for the remaining classes.

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