Skip to main content
A newer version of this page is available. .

Rename Namespace To Match Folder Structure

  • 2 minutes to read

Purpose

Used to bring the name of the namespace in line with the location of the source code file containing the namespace definition. The best coding practices require each namespace name to correspond the physical location of the file containing its definition.

NOTE
  • Rename Namespace To Match Folder Structure is a cascading Refactoring. That means that the Refactoring affects all method calls and method declarations in interfaces, base and descendant classes.
  • Rename Namespace To Match Folder Structure is a cross-language Refactoring. This means that this Refactoring can make required changes in projects in any supported language (see the code snippet below).

Availability

Available when the cursor is on a namespace name in its definition, assuming that this name differs from the path to the source code file containing the namespace definition.

Usage

  1. Place the caret on a namespace name in its 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 physical location of the file containing the namespace definition.

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

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