ReSharper Web Help

The Extract Class From Parameters refactoring allows you to quickly create a new class or structure using the parameters of a given method. ReSharper analyses the selected method and detects the variables that can be converted into members. After extraction, the new class is created with the necessary fields generated from the selected method's parameters.

To extract a class from parameters
  1. Place the caret at the name of a method in the editor or select the method in the File Structure window, in Object Browser or in Class View.
  2. Do one of the following:
    • On the main menu, choose ReSharper | Refactor | Extract Class From Parameters.
    • Right-click the type, then click Refactor | Extract Class From Parameters on the context menu.
    • Press Ctrl+Shift+RCtrl+Shift+R, then click Extract Class From Parameters.
  3. The Extract Class From Parameters dialog box opens. Click one of the radio buttons in the Create section to specify whether you want to create a class or a structure.

    Refactorings__Extract_Class_from_Parameters__dialog_box

  4. Click a radio button in the Declare as section to specify how you want to declare the new class or structure:
    • Nested means that the class should be declared inside the selected method.
    • Top-level means that the class should be declared inside the class where the method is declared.
  5. Type a new class name in the Name text box.
  6. In the Parameters converted to fields list, select the parameters that should be included in the new type. Click Select All to select all parameters quickly.
  7. Click Next. If no conflicts are found, ReSharper performs the refactoring immediately and the new type is created in the same file. Otherwise, resolve conflicts.

Consider the example below:

Refactorings__Extract_Class_from_Parameters_01

After applying the refactoring the FormatParams class is created. All method parameters are replaced with a single parameter of the FormatParams type.

Refactorings__Extract_Class_from_Parameters_02


This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available

Tip

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