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.
- 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.
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.
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.
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.
- Type a new class name in the Name text box.
- 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.
- 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:
After applying the refactoring the FormatParams class is created. All method parameters are replaced with a single parameter of the FormatParams type.
This feature is supported in the following languages/technologies:
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.