Inline Method (and delete)

Purpose

Replaces the current method call(s) with the method's body and deletes the method. Use this Refactoring when the method is trivial or called only once.

Availability

Available when the caret is on a method's name within the method call or declaration. Being executed from the method declaration, this Refactoring affects all method calls.

Usage

  1. Place the caret on the method name.

    Note

    The blinking cursor shows the caret's position at which the Refactoring is available.

    public static double ConvertToUSD(Currency source, double amount) {
        return amount / GetCurrencyRate(source);
    }
    static void Main(string[] args) {
        double price = ConvertToUSD(Currency.JPY, 888);
        // ...
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Inline Method (and delete) from the menu.

After execution, the Refactoring replaces the method call with the method body contents and deletes the method. Each parameter reference in the method's scope is replaced with the corresponding variable or constant from the outer scope.

static void Main(string[] args) {
    double price = 888 / GetCurrencyRate(Currency.JPY);
    // ...
}
Note

If the method was called with an expression as a parameter, the Refactoring introduces a local variable before inlining the method.

See Also