Back to Devexpress

Inline Method and Delete

coderushforroslyn-115539-refactoring-assistance-inline-method-and-delete.md

latest1.8 KB
Original Source

Inline Method and Delete

  • Jul 13, 2021
  • 2 minutes to read

Purpose

Replaces the current method call(s) with the method’s body and deletes the method. Use this refactoring when the method has a simple structure or is called only once.

Availability

This refactoring is available when the caret is in a method’s name inside the method call or declaration. This refactoring affects all method calls If you run it from the method declaration.

Usage

  1. Place the caret in a method name.

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

  3. Select Inline Method and Delete from the menu.

After execution, this refactoring replaces the method call with this method body content and deletes the method. Each parameter reference in the method’s scope is replaced with the corresponding variable or constant from the outer scope.

csharp
static void Main(string[] args) {
    double price = 888 / GetCurrencyRate(Currency.JPY);
    // ...
}
vb
Shared Sub Main(ByVal args() As String)
    Dim price2 As Double = 888 / GetCurrencyRate(Currency.JPY)
    ' ...
End Sub

Note

If the method is called with an expression as a parameter, the Inline Method and Delete refactoring introduces a local variable before inlining the method.

See Also

Inline Method

Inline Temp

Promote to Parameter

Widen Scope

Decompose Parameter