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.
To 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+Shift+R and then choose Adjust Namespaces
- Right-click and choose Refactor | Adjust Namespaces on the context menu.
- Choose in the main menu.
- 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.
ReSharper 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: