ReSharper 2023.3 Help

Inline Class refactoring

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.

In the example below, we merge the Painter class (that is, its field myColor and its method InitPainter) into the Circle class.

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); } }
class Circle { private Color myColor; public Circle(Color c) { myColor = c; InitPainter(myColor); } private void InitPainter(Color color) { //init painter } }

Inline a class

  1. 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 File Structure window.

  2. Do one of the following:

    • Press Control+Alt+N and then choose Inline Class

    • Press Control+Shift+R and then choose Inline Class.

    • Right-click and choose Refactor | Inline Class from the context menu.

    • Choose ReSharper | Refactor | Inline | Inline… from the main menu.

  3. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.

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.

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 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 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: 18 March 2024