This command is a bulk fix that helps you synchronize namespaces with folder structure in any scope, which can be as large as your whole solution. That is, if a namespace in some file does not correspond to the location of the file in the project structure, the namespace is renamed according to the file location and all using directives referencing the modified namespaces are updated.
By default, JetBrains Rider 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:
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 select the folder and open its properties. Then, clear the Namespace Provider checkbox.
A folder which is not a Namespace Provider will not influence the namespace of elements it contains, and JetBrains Rider will analyze and refactor the related code accordingly.
Synchronize namespaces with project structure
In the Solution Explorer, select a node where you want to synchronize namespaces.
Do one of the following:
Press Ctrl+Alt+Shift+T and then choose Adjust Namespaces.
Choosefrom the main menu.
The Adjust Namespaces dialog will open.
Check the list of files where namespaces do not correspond to the project structure and select files where you want to synchronize namespaces.
To apply the refactoring, click Next.
If there are no conflicts, the refactoring is performed immediately. If there are types or delegates with same names, which get into the same namespace after the refactoring, the wizard displays a page with conflicts. You can double-click conflicts to navigate to the corresponding declarations and fix them.
JetBrains Rider also provides a code inspection that detects mismatching namespaces. By default, the inspection reports a warning if there is a single namespace declaration in the file and it does not correspond file location in the project structure.
You can synchronize mismatching namespace right from the editor by pressing Alt+Enter and using the corresponding quick-fix: You can also apply the quick-fix in a larger scope, which will give you the same result as performing the refactoring: