ReSharper 2021.2 Help

Pull Members Up refactoring

This refactoring helps to move type members and implemented interfaces from a derived type up the inheritance hierarchy to a base type. For example, if you have MyDerivedClass : MyBaseClass, IMyInterface, this refactoring can help you move members of MyDerivedClass to MyBaseClass or IMyInterface or to any of their ancestors. The refactoring can also move the entire implementation of IMyInterface to MyBaseClass or any of its ancestors.

In the example below, we invoke the refactoring on MyDerivedClass to add void Foo() implemented there to IMyInterface:

interface IMyInterface { } class MyDerivedClass : IMyInterface { public void Foo() { Console.WriteLine("Hello"); } }
interface IMyInterface { void Foo(); } class MyDerivedClass : IMyInterface { public void Foo() { Console.WriteLine("Hello"); } }

Pull members up

  1. Select a type in one of the following ways:

    • In the editor, set the caret at the name of a type.

    • Select a type in the Solution Explorer.

    • Select a type in the File Structure window.

    • Select a type in the Class View.

    • Select a type in the Object Browser.

    • Select a type in the type dependency diagram.

    Or, alternatively, select a member in the editor or in a tool window.
  2. Do one of the following:

    • Press Control+Shift+R and then choose Pull Members Up

    • Right-click and choose Refactor | Pull Members Up in the context menu.

    • Choose ReSharper | Refactor | Pull Members Up… in the main menu.

    The Pull Members Up dialog will open.

  3. Select a destination base type from the list of available types. Base types are displayed as a reversed hierarchy where types from the top of the hierarchy are displayed as most inner nodes.

  4. Select members and/or interfaces that you want to move. You can also click All Public to quickly select all public members and/or Dependent to select members that are referenced by other selected members, implement the selected interfaces, or override members in base classes.

  5. For any member, you can select Make abstract (if applicable) to create an abstract member in the target base class and leave its implementation in the current class.

  6. To apply the refactoring, click Next.

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

ReSharper. Pull Members Up refactoring

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is available in Visual Basic .NET 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 details specific to other languages, see corresponding topics in the ReSharper by language section.

Last modified: 08 March 2021