ReSharper 2018.3 Help

Fix inconsistent namespace naming

You have probably seen that, when the namespace declaration does not match the file location and/or project settings, ReSharper warns you about it and allows you to correct it:

ReSharper quick-fix to synchronize namespace to the file location

However, if you have several files with incorrect namespaces, going through them one by one can be a pain. Luckily, you can simply press Ctrl+Shift+R on a node in the Solution Explorer and select Adjust Namespaces:

ReSharper helps fix namespaces in a project

This will pop up a dialog letting you select all files where namespaces need to be adjusted:

Synchronizing namespaces with project structure

After you pick the namespaces to fix, they will be adjusted to their expected values (dependent upon project settings and file location).

By default, ReSharper assumes that the namespace each class appears in matches its location in the project. The 'root' namespace for the project is defined in the project properties:

ReSharper code inspection: Namespace does not correspond to file location

As a result of the above, all code elements at the project level are expected to appear in the Nancy.Embedded namespace, and a warning will be issued otherwise.

Namespaces are made deeper with the introduction of folders. In the example below, a folder called Conventions will necessitate all items it contains to appear in the Nancy.Embedded.Conventions namespace. However, there are cases where you do not need the folder to append an extra namespace element. In such cases, you can set Namespace Provider to False in the Project Item Properties popup, which you can invoke by selecting Edit project item properties from the context menu of the folder in the Solution Explorer.

ReSharper: 'Namespace provider' property of a project folder

A folder which is not a Namespace Provider will not influence the namespace of elements it contains, and ReSharper will analyze and refactor the related code the accordingly.

Last modified: 15 April 2019

See Also