ReSharper Help

Convert Interface to Abstract Class

ReSharper | Refactor | Convert | Method to Indexer…
ReSharper_Function2Indexer

This refactoring converts interfaces into abstract classes thus helping you quickly change hierarchical dependency among a set of classes and interfaces.

Consider the following example:

Before refactoringAfter refactoring
interface Shape { double Area { get; } void Draw(); } class Circle : Shape { private readonly int radius; public double Area { get { return Math.PI*Math.Pow(radius, 2); } } public void Draw() { //do something } }
abstract class Shape { public abstract double Area { get; } public abstract void Draw(); } class Circle : Shape { private readonly int radius; public override double Area { get { return Math.PI*Math.Pow(radius, 2); } } public override void Draw() { //do something } }

To turn a suitable interface into an abstract class

  1. Select an interface in one of the following ways:
    • In the editor, set the caret at the name of an interface.
    • Select an interface in the Solution Explorer.
    • Select an interface in the File Structure window.
    • Select an interface in the Class View.
    • Select an interface in the Object Browser.
    • Select an interface in the type dependency diagram.
  2. Do one of the following:
    • On the main menu, choose ReSharper | Refactor | Convert | Method to Indexer…
    • Right-click and choose Refactor | Convert Interface to Abstract Class on the context menu.
    • Press Ctrl+Shift+R and then choose Convert Interface to Abstract Class
  3. 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:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available

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.

See Also

Last modified: 30 June 2015