Back to Devexpress

Rename Type to Match File

coderushforroslyn-115572-refactoring-assistance-rename-type-to-match-file.md

latest1.5 KB
Original Source

Rename Type to Match File

  • Aug 03, 2020
  • 2 minutes to read

Purpose

Used to bring the name of the type declared in the file in line with a source code file name. The best coding practices require each type to be declared in a separate file named after the type.

Note

Rename Type To Match File is a cascading Refactoring. That means that the Refactoring affects all method calls and method declarations in interfaces, base and descendant classes.

Availability

Available when the cursor is on a type name, assuming the file name differs from it.

Usage

  1. Place the caret on a class name.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Rename File to Match Type from the menu.

After execution, the Refactoring changes the type name to match the file name.

csharp
//Filename: Person.cs
public class Person {
    private int CustomerID;
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
vb
'Filename: Person.vb
Public Class Person
    Private CustomerID As Integer
    Public Property FirstName() As String
    Public Property LastName() As String
End Class

See Also

Rename File to Match Type

Move Type to File