Rename Namespace to Match Folder Structure

  • 2 minutes to read

Purpose

Renames a namespace name according to the project default namespace and the path to the source code file in which the namespace is declared.

NOTE

Rename Namespace To Match Folder Structure is a cascading refactoring. It affects all method calls and method declarations in interfaces, base and descendant classes.

Availability

Available when the cursor is in a namespace name definition. The namespace name should be different than the path to the source code file which contains the namespace definition.

How to Use

  1. Place the caret in a namespace name declaration.

    NOTE

    The blinking cursor shows the caret's position at which the Refactoring is available.

    //File path: DevExpress.CodeRush.TestRunner\Options\TestRunnerOptionsPage.xaml.cs
    
    namespace TestRunnerOptions {
        // ...
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Rename Namespace to Match Folder Structure from the menu.

After execution, the Refactoring changes the name of the namespace to match the location of the file which contains the namespace definition.

//File path: DevExpress.CodeRush.TestRunner\Options\TestRunnerOptionsPage.xaml.cs

namespace DevExpress.CodeRush.TestRunner.Options {
    // ...
}

XAML Support

You can run Rename Namespace to Match Folder Structure in:

  • XAML file

    RemoveQualifier

  • XAML code behind file

    RemoveQualifier

Sync Namespace with Folder Structure

You can use the Sync Namespace with Folder Structure item in the Solution Explorer's context menu. This item is available for folders and projects which contain files with incorrect namespaces.

RemoveQualifier