ReSharper 2020.2 Help

Transform Parameters refactoring

ReSharper | Refactor | Convert | Transform parameters…

This refactoring helps you quickly change method signature by transforming parameters — for example, get rid of out parameters, wrap parameters in a tuple or in a new class, and so on. — and automatically update all usages of the method in your solution.

The refactoring lets you perform the following transformations:

  • Create a new class with public fields or auto-properties for types corresponding to the selected parameters, and use the newly created class instead of parameters.

  • Replace parameters with a tuple object.

  • For a method returning void, transform a selected out parameter to method return.

  • For a method returning void, wrap multiple selected out parameters to a tuple object and use it as method return.

  • For a method returning void, create a new class with public fields or auto-properties for types corresponding to the selected out parameters, and use the newly created class as method return.

  • For non-void methods with out parameters, combine out parameters with return type in a tuple object or in a newly created class.

The example below demonstrates a mix of transformations - we replace out parameter with method return, and we wrap two other parameters with a new class:

class TestClass { public void DrawCircle(Point ctr, float rad, out bool res) { // draw... res = true; } }
class TestClass { public bool DrawCircle(Circle circle) { // draw... . var res = true; return res; } } internal class Circle { public Circle(Point ctr, float rad) { Ctr = ctr; Rad = rad; } public Point Ctr { get; private set; } public float Rad { get; private set; } }

Transform method parameters

  1. Place the caret at the declaration or a usage of method in the editor, or select the method in the File Structure window. Or, alternatively set the caret at any of method parameters.

  2. Do one of the following:

    • Press Control+Shift+R and then choose Transform Parameters

    • Right-click and choose Refactor | Transform Parameters in the context menu.

    • Choose ReSharper | Refactor | Convert | Transform parameters… in the main menu.

    The Transform Parameters dialog will open.

  3. Select parameters you want to transform.

  4. Depending on selected in/out parameters, ReSharper enables Method receives and/or Method returns selectors. Use these selectors to choose how in/out parameters should be transformed. If you choose to create a new class for parameters, you will be able to specify its name in a field to the right of it.

  5. To apply the refactoring, click Next.

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

ReSharper. Transforming method's parameters

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is available in Visual Basic .NETFeature is not available in C++Feature is not available in HTMLFeature is not available in ASP.NETFeature is not available in RazorFeature is not available in JavaScriptFeature is not available in TypeScriptFeature is not available in CSSFeature is not available in XMLFeature is not available in XAMLFeature is not available in Resource filesFeature is not available in build script filesFeature is not available in ProtobufFeature is not available in JSON

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.

Last modified: 03 September 2020