Move Type to File

Purpose

Moves a type declaration to a new source code file. The best coding practices require each type to be declared in a separate file. Use this Refactoring to easily isolate a type in a separate source file.

Availability

Available when the caret is on a type declaration and the file contains two or more types. The type should have a name that differs from the file name.

Usage

  1. Place the caret on a class declaration.

    Note

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

    public class Person {
        //...
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Move Type to File from the menu.

After execution, the Refactoring creates a new source file named after the type, adds it to the project and moves the type to that file. All leading comments, attributes, and XML doc comments are moved to the new file together with the type itself. All references used by the type are added to the new file automatically.

See Also