ReSharper | Refactor | Convert | Method to Indexer…
To assign a shortcut, go to Tools | Options | Environment | Keyboard and find the ReSharper_Function2Indexer command.
This refactoring converts interfaces into abstract classes thus helping you quickly change hierarchical dependency among a set of classes and interfaces.
publicdouble Area => Math.PI * Math.Pow(radius,2);
publicvoidDraw()
{
//do something
}
}
After refactoring
abstractclassShape
{
publicabstractdouble Area {get;}
publicabstractvoidDraw();
}
classCircle:Shape
{
privatereadonlyint radius;
publicoverridedouble Area => Math.PI * Math.Pow(radius,2);
publicoverridevoidDraw()
{
//do something
}
}
tip
After performing this refactoring, you may want to bring some members from derived classes to the newly created abstract class. You can do it with the Pull Members Up refactoring.
Convert an interface into an abstract class
Select an interface in one of the following ways:
In the editor, place the caret at the name of an interface.
Press CtrlShift0R 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.
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.