ReSharper Web Help

The Introduce Parameter refactoring allows you to add a new parameter into a method or constructor from an expression inside its body. All calls to the method/constructor are automatically updated with the appropriate value passed as the new parameter.

If an expression that you want to pass as a parameter references symbols declared in the method body, ReSharper allows to "en-lambda" these symbols by introducing a delegate parameter and using it to pass a lambda expression from the caller (see procedure below for an example).

To introduce a parameter to a method or constructor
  1. In the code editor, select an expression inside a method or constructor:
    Refactorings__Introduce_Parameter__before.png
  2. Choose ReSharper | Refactor | Introduce Parameter, or press Ctrl+Alt+P.
    • If the selected expression occurs two or more times in the current method or constructor, ReSharper asks to specify how many occurrences it should replace:
      Refactorings__Introduce_Parameter__replace_occurrences.png
    • If the selected expression occurs only once, the Introduce Parameter wizard opens immediately:
      Refactorings__Introduce_Parameter__dialog_box.png
  3. Specify the following options:
    • In the Parameter name text box, choose a suggested name for the new parameter, or enter a custom name.
    • If the selected expression requires passing the parameter as a lambda expression, select members to en-lambda in the Select local variables to en-lambda section.
  4. Click Next. If ReSharper discovers no conflicts, the refactoring is applied immediately. The following figure shows how ReSharper generates a delegate parameter:
    Refactorings__Introduce_Parameter__after.png
    This is how a method call transforms to pass a lambda expression:
    Refactorings__Introduce_Parameter__call.png

See Also

Procedures