coderushforroslyn-115538-refactoring-assistance-inline-method.md
Replaces the current method call(s) with the method’s body without deleting the method. Use this Refactoring if you need to edit the method for the current call only and leave the rest of the code unchanged.
Available when the caret is on a method’s name within the method call or declaration. Executed from the method declaration, this Refactoring replaces all method calls with the method’s body.
Place the caret on the method name.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
Select Inline Method from the menu.
After execution, the Refactoring replaces the method call with the method body contents. Each parameter reference in the method’s scope is replaced with the corresponding variable or constant from the outer scope.
public static double ConvertToUSD(Currency source, double amount) {
return amount / GetCurrencyRate(source);
}
static void Main(string[] args) {
double price1 = 10 / GetCurrencyRate(Currency.EUR);
double price2 = ConvertToUSD(Currency.JPY, 888);
// ...
}
Public Shared Function ConvertToUSD(ByVal source As Currency, ByVal amount As Double) As Double
Return amount / GetCurrencyRate(source)
End Function
Shared Sub Main(ByVal args() As String)
Dim price1 As Double = 10 / GetCurrencyRate(Currency.EUR)
Dim price2 As Double = ConvertToUSD(Currency.JPY, 888)
' ...
End Sub
Note
If the method was called with an expression as a parameter, the Refactoring introduces a local variable before inlining the method.
See Also