Inline Class refactoring
Refactor | Inline...
This refactoring allows you to merge one class into another class. The class that you merge in is removed, its members are moved to the class where the merged class is used, and all usages of the merged class are updated accordingly.
tip
The reverse functionality is available with the Extract Class refactoring refactoring.
In the example below, we merge the Painter
class (that is, its field myColor
and its method InitPainter
) into the Circle
class.
Before refactoring
class Painter{ private Color myColor; public Painter(Color c) { myColor = c; InitPainter(myColor); } private void InitPainter(Color color) { //init painter }}class Circle{ private Painter myPainter; public Circle(Color c) { myPainter = new Painter(c); }}
After refactoring
class Circle{ private Color myColor; public Circle(Color c) { myColor = c; InitPainter(myColor); } private void InitPainter(Color color) { //init painter }}
Place the caret at the name or a usage of a property or a field that represents the class that you want to merge in. Or, alternatively, select a property or a field in the Structure window window.
Do one of the following:
Press and then choose Inline Class
Press CtrlShift0R and then choose Inline Class.
Choose Refactor | Inline Class from the main menu.
If no conflicts are found, JetBrains Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
tip
Right after the refactoring has been completed, all changes that it makes anywhere, including other files, are registered as a single operation. So you can use the Undo action Ctrl0Z to roll back all these changes with a single keystroke.
After applying the refactoring the property or the field is replaced with members of its type. All usages of the property or the field are updated accordingly.