Move a type to a matching file refactoring
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This refactoring applies to:
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.
Place the cursor inside the name of the type where it is defined. For example:
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.