Programming with Castalia : Refactoring : Inline Temporary Variable
Previous  Top  Next

You have a local variable that is being assigned to a simple expression, and may be getting in the way of other refactorings.

Remove the variable, replacing all references to the variable with the original expression.

function GetOrderPrice(ProductID, Quantity: Integer): Currency;  
var  
  BasePrice: Currency;  
begin  
  BasePrice := GetProductBasePrice(ProductID);  
  Result := BasePrice * Quantity;  
end;  
 
downarrow  
 
function GetOrderPrice(ProductID, Quantity: Integer): Currency;  
begin  
  Result := GetProductBasePrice(ProductID) * Quantity;  
end;  
 
This refactoring is the opposite of Introduce Explaining Variable.
 
To inline a variable, place the cursor in the name of the variable to be inlined, and invoke the Inline Temporary Variable refactoring. Castalia will remove the variable from the method, replacing all instances of the variable with the expression assigned to the variable.

See also: Refactoring Overview, Rename Local Variable Refactoring, Split Temporary Variable Refactoring