ReSharper 2023.3 Help

Inline Parameter refactoring

This refactoring allows you to replace a method parameter with argument value from a method call. If there are several calls, you can choose the call to take the argument from.

A simple case. Inlining a constant value of the parameter pi:

private double AreaOfCircle(double rad, double pi) { return pi*rad*rad; } public void Test() { var area = AreaOfCircle(10, Math.PI); }
private double AreaOfCircle(double rad) { return Math.PI*rad*rad; } public void Test() { var area = AreaOfCircle(10); }

If the argument that you want to be inlined depends on other variables and/or calculations, ReSharper can replace the original parameter with other parameter(s) and move the calculations inside the target method.

In the following example, we apply the refactoring to the action parameter of the PerformAction method so that the whole lambda, which was used as an argument in the call moves into the method body, and two new parameters are created to pass necessary values:

private void PerformAction(Action action) { action(); } private void Test(string key, string value) { PerformAction(() => Console.WriteLine("{0} : {1}", key, value)); }
private void PerformAction(string arg0, string value) { ((Action) (() => Console.WriteLine("{0} : {1}", arg0, value)))(); } private void Test(string key, string value) { PerformAction(key, value); }

Inline a parameter

  1. Place the caret at the parameter in the method declaration or at the argument in the method call.

  2. Do one of the following:

    • Press Control+Alt+N and then choose Inline Parameter

    • Press Control+Shift+R and then choose Inline Parameter.

    • Right-click and choose Refactor | Inline Parameter from the context menu.

    • Choose ReSharper | Refactor | Inline | Inline… from the main menu.

    The Inline Parameter dialog will open.

  3. If the method has multiple usages, select the usage whose argument you want to be inlined and click Next.

  4. Select the parameter that you want to inline.

  5. If the inlined argument depends on other variables, ReSharper suggests one or more variables from the caller in the New arguments field. Select the desired arguments.

  6. Check the preview of the new signature and click Next.

  7. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is available in Visual Basic

Feature is not available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the ReSharper by language section.

Last modified: 18 March 2024