Inline Method (and delete)
- 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 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
Place the caret on the method name.
NOTE
The blinking cursor shows the caret's position at which the Refactoring is available.
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- 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.