Move Type to File
- 2 minutes to read
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.
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.
Place the caret on a class declaration.
The blinking cursor shows the caret's position at which the Refactoring is available.
- Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
- Select Move Type to File from the menu.
After execution, 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.
You can configure whether CodeRush opens a generated file whet it applies this refactoring. Refer to the Code Actions Settings topic for more information.