Skip to main content

Move Type to Namespace

  • 2 minutes to read

Purpose

Moves a type to a namespace or file-scoped namespace (for C # 10), and updates all references.

Availability

Available when the caret is in a type declaration and a solution contains two or more namespaces.

How to Use

  1. Place the caret in a type declaration.

    Note

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

    namespace NS1 {
        class Class1 {
            // ...
        }
        class Class2 {
            // ...
        }
    }
    
    namespace NS2 {
        class Class3 {
            // ...
        }
    }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Move Type to Namespace from the menu.

Do one of the following actions in the sub menu:

Select a namespace from the list and press Enter to move a type to the existing namespace.

RemoveQualifier

Note

If the target namespace list is too large, CodeRush shows its part. To filter the list, type a namespace name when the menu is open.

Type a namespace name and press Ctrl+Enter or Enter to move a type to a new namespace.

RemoveQualifier

After execution, this refactoring moves the type to the namespace and updates all references.

For example, you can run Move Type to Namespace for the code above to move Class2 to the NS2 namespace.

namespace NS1 {
    class Class1 {
        // ...
    }
}

namespace NS2 {
    class Class3 {
        // ...
    }
    class Class2 {
        // ...
    }
}

If a file contains namespaces and the target namespace is not in this file, CodeRush moves the type to a separate file.

RemoveQualifier

Move Type to Namespace changes the namespace if a file contains one namespace (see examples in the XAML Support section).

XAML Support

You can run the Move Type to Namespace refactoring in the following file types:

XAML code behind files

RemoveQualifier

XAML files

RemoveQualifier