Extract an Interface from a Class in JetBrains Rider
Extract an interface from a C# class in JetBrains Rider using Refactor This, then verify with dotnet build.
15 Apr 2026, 19:01 UTC

Problem and takeaway
You have a concrete C# class whose methods and properties are referenced directly by other code. When you need to swap the implementation—for example, to insert a test double or an alternative service—every consumer still depends on the concrete type, so the change ripples through the solution.
Useful takeaway: Rider's Refactor This command can extract an interface from selected members of a class, generate the interface file, declare that the class implements it, and optionally update existing usages to reference the interface instead.
Prerequisites
- JetBrains Rider installed, recent stable major release. Confirm the build in Help | About before starting.
- A C# solution open in Rider containing the class you want to refactor.
- The class exposes public members (methods, properties, or events) that you want to include in the interface.
- Write permission for the project files and, if applicable, your version-control working directory.
Procedure: extract an interface
- Open the class. In Solution Explorer, open the C# file that contains the target class.
- Position the caret. Click inside the class declaration, or select the specific members to include.
- Open Refactor This. Press Ctrl+Shift+R on Windows or Linux, or Ctrl+T on macOS. You can also right-click the class and choose Refactor This.
- Choose Extract Interface. From the menu, select Extract Interface.
- Configure the extraction. In the dialog:
- Enter an interface name, commonly prefixed with I, such as IOrderProcessor.
- Select the members to include.
- Choose where to create the interface file: the same file, a new file, or a specific folder.
- Decide whether to update usages so existing references target the new interface.
- Preview and apply. Review the preview pane listing files to be created or modified, then click Next or Apply.
Example configuration
Given a class OrderProcessor with methods Process(Order) and Cancel(int), the dialog might be configured as follows:
| Setting | Value |
|---|---|
| Interface name | IOrderProcessor |
| Members to extract | Process(Order), Cancel(int) |
| Destination | New file: IOrderProcessor.cs |
| Update usages | Yes |
After applying, Rider creates IOrderProcessor.cs, changes the class declaration to public class OrderProcessor : IOrderProcessor, and updates selected call sites to use the interface type where the refactoring engine can safely infer it.
Expected checks
- The new interface file appears in Solution Explorer under the chosen project or folder.
- The original class declaration includes the interface in its base list.
- Build the solution. In Rider's integrated terminal (View | Tool Windows | Terminal), at the solution root, run:
Where to run: Rider integrated terminal. Permissions: normal file access only. Placeholder: replace <SolutionName> with your solution file name. Expected check: the build completes with no errors. Risk: the command compiles code and does not modify source, but a failed build may indicate that extraction introduced a type mismatch.dotnet build '<SolutionName>.sln' - Open a consumer file that was updated. Verify that variables or parameters now reference the interface rather than the concrete class.
Limitations
- Rider cannot include private members in the extracted interface.
- If the class relies on members not being extracted, the interface may not fully describe its behavior, and some consumers may still need casts to the concrete type.
- Refactoring availability and behavior vary between Rider major releases and .NET SDK versions. Older .NET Framework projects may have limited support.
- Some Rider features require an active license and may be subject to organizational restrictions.
Recovery options
Extract Interface creates and modifies files, so it changes repository state. To undo:
- Press Ctrl+Z on Windows or Linux, or Cmd+Z on macOS, to revert the refactoring through Rider's local history.
- If you already committed, revert the commit or restore affected files from the previous commit in your version-control tool.
- If the build fails after extraction, inspect the refactoring preview, adjust member visibility or interface membership, and repeat the extraction.
Practical verification
Open Help | About and confirm the installed Rider build matches a recent stable release. Then load a C# solution, invoke Refactor This on a method, and confirm the suggested transformation appears and applies without errors before using it on production code.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.