ReSharper 2024.2 Help

Convert Interface to Abstract Class refactoring

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:

interface Shape { double Area { get; } void Draw(); } class Circle : Shape { private readonly int radius; public double Area => 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 => Math.PI * Math.Pow(radius, 2); public override void Draw() { //do something } }

Convert an interface into an abstract class

  1. Select an interface in one of the following ways:

    • In the editor, place the caret at the name of an interface.

    • Select an interface in the Solution Explorer.

    • Select an interface in the File Structure window 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:

    • Press Control+Shift+R and then choose Convert Interface to Abstract Class.

    • Right-click and choose Refactor | Convert Interface to Abstract Class from the context menu.

    • Choose ReSharper | Refactor | Convert | Method to Indexer… from the main menu.

  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 and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is available in Visual Basic

Feature is not available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

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 ReSharper by language section.

Last modified: 23 September 2024