Move a type to a matching file refactoring
Applies to: Visual Studio
Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
This refactoring applies to:
C#
Visual Basic
What: Lets you move the selected type to a separate file with the same name.
When: You have multiple classes, structs, interfaces, etc. in the same file which you want to separate.
Why: Placing multiple types in the same file can make it difficult to find these types. By moving types to files with the same name, code becomes more readable and easier to navigate.
How-to
Place the cursor inside the name of the type where it is defined. For example:
class Person
Class Person
Next, do one of the following:
- Press Ctrl+.
- Right-click on the type name and select Quick Actions and Refactorings
Select Move type to TypeName.cs from the menu, where TypeName is the name of the type you've selected.
The type is moved to a new file in the project that has the same name as the type.
C#:
Visual Basic: