The Extract Class refactoring allows you to extract a new class with members of some existing class. For example, this refactoring is useful when you need to replace a single class that is responsible for multiple tasks with several classes each having a single responsibility.
- Place the caret at the name of a class in the editor or select the class 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.
- Right-click the type, then click Refactor | Extract Class on the context menu.
- Press Ctrl+Shift+R, then click Extract Class.
- The Extract Class dialog box opens. Type a name for a new class in the Extracted class text box.
- Specify names for references to the extracted class in the Reference to extracted text box and to the existing class in the Reference to source text box or leave the suggested ones.
- Select members to be extracted into the class. ReSharper may suggest to extract additional members by marking them with Extract word. Click Extract all suggested members to extract all of them.
Specify the location for the extracted class:
- Click same file as the source class to place the new class in the same file as the original class.
- Click its own file to place the new class in a separate file.
- Click Next to apply the refactoring. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, resolve conflicts.