Extract Interface refactoring
This refactoring helps create a new interface based on a selected type.
ReSharper suggests you to choose which members should be transferred to the new interface.
After extraction, the original type is updated to implement the new interface.
If the current type already implements any interfaces, these interfaces can be also extracted into the new interface.
In the example below, the
Color property and the
Draw method of the
Circle class are extracted to create a new interface:
To extract an interface from a type
- Select a type in one of the following ways:
Do one of the following:
- Press Ctrl+Shift+R and then choose Extract Interface
- Right-click and choose Refactor | Extract Interface in the context menu.
- Choose in the main menu.
- Specify a name for the interface and where it should be placed - in a new file or in the same file as the original type.
- Select members that you want to transfer to the new interface. The list of members can contain:
- To quickly select all public members, click All Public.
- If you have selected members that reference other members, the latter are highlighted with red. Click Dependent to resolve the conflict, i.e. to select any members that depend on the currently selected members.
- To apply the refactoring, click Next.
- 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/technologies:
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.