Back to Devexpress

Inline Temp

coderushforroslyn-115550-refactoring-assistance-inline-temp.md

latest1.5 KB
Original Source

Inline Temp

  • Aug 03, 2020
  • 2 minutes to read

Purpose

This Refactoring replaces all references to a local variable with its initial value.

You may find a variable in your code whose value does not change and the meaning is trivial. If this variable is not commonly used, you can eliminate it by executing the Inline Temp Refactoring.

Availability

Available when the cursor is on a local variable declaration or reference assuming the variable does not change.

Usage

  1. Place the caret on a local variable whose value does not change.

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

  3. Select Inline Temp from the menu.

After execution, the Refactoring replaces the variable references with its initial value and removes the initialization.

csharp
float CalculateDiscount(float price) {
    int percentage = GetCurrentDiscount();
    return price - (float)percentage / 100 * price;
}
vb
Private Function CalculateDiscount(ByVal price As Single) As Single
    Dim percentage As Integer = GetCurrentDiscount()
    Return price - CSng(percentage) / 100 * price
End Function

See Also

Promote to Parameter

Widen Scope

Inline Method and Delete