ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Introduce Parameter refactoring

Last modified: 21 July 2022

ReSharper | Refactor | Introduce Parameter…

Ctrl+R P (ReSharper_IntroduceParameter)

This refactoring allows you to move an expression from a method implementation to its callers by adding a new parameter. All occurrences of the expression are replaced with the new parameter; all calls to the method in the solution are updated with the new argument.

In the example below, we use this refactoring to replace two occurrences of the same string with a parameter. The string itself is moved to the caller argument:

If the expression that you want to pass as a parameter references symbols declared in the method body, ReSharper allows you to 'en-lambda' these symbols by introducing a generic delegate parameter and using it to pass a lambda expression from the caller. In the example below, we invoke the refactoring for the "The current time is: " + currentTme expression:

ReSharper: 'Introduce Parameter' refactoring

This feature is supported in the following languages and technologies:

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by language section.