ReSharper Help

Inline Class

ReSharper | Refactor | Inline | Inline…
Ctrl+Alt+N
ReSharper_InlineVariable

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 current class, and all usages of the merged class are updated accordingly.

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

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

To 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 Ctrl+Alt+N and then choose Inline Class
    • Press Ctrl+Shift+R and then choose Inline Class
    • Right-click and choose Refactor | Inline Class on the context menu.
    • Choose ReSharper | Refactor | Inline | Inline… in 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/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available 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: 3 September 2015