ReSharper Web Help

The Move Instance Method refactoring allows you to move an instance (non-static) method to another type. In contrast to moving static members, instance method cannot be moved to just any type. The list of potential target types includes types of the method parameters and types of fields in the current type.

This refactoring may be helpful if you see that the logic of a method suits better for the type that is passed as the method parameter or a field rather than for the current type.

Consider the following example:

Moving instance method

The method StartTheCar clearly belongs to the Car class. So, ReSharper helps us to move this method exactly there:

Moving instance method

Note that the refactoring would do the same if the Car were used as a filed in the Person type.

To move an instance method
  1. Place the caret at the name of the method that you want to move.
  2. Do one of the following:
    • On the main menu, choose ReSharper| Refactor | Move Instance Method.
    • Choose Refactor | Move Instance Method on the context menu.
    The Move Instance Method dialog box opens.
  3. Select the destination type if there are multiple suggestions.
  4. Optionally, change the access modifier.
  5. Click Next.
  6. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise,resolve conflicts.

Refactorings__Move__Instance_Method_to_Another_Type

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

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

Procedures: