The Extract Interface refactoring helps create a new interface based on a selected interface or class.
ReSharper analyses the selected interface or class to detect members that can be transferred to the new interface. After extraction, the original interface or class is updated to implement the new interface.
- In the editor, position the caret at the declaration of interface or class that you want to extract an interface from.
- Choose ReSharper | Refactor | Extract Interface.
- The Extract Interface wizard opens:
- Members of the current class.
- Members of any base classes or interfaces that the selected class currently inherits/implements.
- Names of interfaces that the selected class currently implements.
- In the Name of new interface text box, type a name for the new interface.
- Click Place beside or Place in another file to define the physical location of the new interface.
- In the list of members, select members that you want to transfer to the new interface.
NoteIf you select the name of an interface that the refactored interface or class implements, it will be implemented in the extracted interface instead of the current class/interface. For example, it you refactor interface
ICurrentthat implements interface
IImplemented, and you select the name of
IImplementedin the list of members, then after the refactoring is completed,
ICurrentwill implement the newly created interface
INew, which will in turn implement
- To extract all listed 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.
- Click Next. If no conflicts are found, the refactoring will be applied immediately.