ReSharper 2018.1 Help

Adjust Namespaces

adjust namespaces

ReSharper | Refactor | Adjust Namespaces…

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

  1. In the Solution Explorer, select a node where you want to synchronize namespaces.
  2. Do one of the following:
    • Press Ctrl+Shift+R and then choose Adjust Namespaces
    • Right-click and choose Refactor | Adjust Namespaces in the context menu.
    • Choose ReSharper | Refactor | Adjust Namespaces… in the main menu.
    The Adjust Namespaces dialog will open.
  3. Check the list of files where namespaces do not correspond to the project structure and select files where you want to synchronize namespaces.
    Synchronizing namespaces with project structure
  4. To apply the refactoring, click Next.
  5. 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:

ReSharper quick-fix to synchronize namespace to the file location
Last modified: 20 August 2018

See Also