Extract Interface refactoring
ReSharper | Refactor | Extract | Extract Interface…
To assign a shortcut, go to Tools | Options | Environment | Keyboard and find the ReSharper_ExtractInterface
command.
This refactoring helps create a new interface based on a selected type. ReSharper suggests choosing members to 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, those interfaces can also be 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:
Before refactoring
class Circle{ public Point Center { get; private set; } public Color Color { get; private set; } public int Radius { get; private set; } public void Draw() { // draw... }}
After refactoring
interface IShape{ Color Color { get; } void Draw();}class Circle : IShape{ public Point Center { get; private set; } public Color Color { get; private set; } public int Radius { get; private set; } public void Draw() { // draw... }}
tip
You can also extract a base class from the current class using the Extract Superclass refactoring refactoring.
Select a type in one of the following ways:
In the editor, place the caret at the name of a type.
Select a type in the Solution Explorer.
Select a type in the File Structure window window.
Select a type in the Class View.
Select a type in the Object Browser.
Select a type in the type dependency diagram.
Do one of the following:
Press CtrlShift0R and then choose Extract Interface.
Right-click and choose Refactor | Extract Interface from the context menu.
Choose ReSharper | Refactor | Extract | Extract Interface… from the main menu.
The Extract Interface dialog will open.
Specify a name for the new 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:
Members of the current type
Members of base types that the selected type currently inherits/implements
Interfaces that the selected type currently implements
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, that is 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 and technologies:
The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the Languages and frameworks section.