Move Static Member

The Move Static Member refactoring allows users to move inner classes, static fields and methods to another type. All corresponding references and usages are automatically updated, including the cases when the member uses other members of its original type.

Note   If you want to move non-static methods, you can perform the following sequence of refactorings: Make Method Static -> Move Static Member -> Make Method Non-static.

To move a static member

  1. Select the static member in Class View or Object Browser, or position the caret at its name in the editor.
  2. Do one of the following:
    • In the main menu, click ReSharper | Refactor | Move.
    • Right-click the type, and in the shortcut menu click Refactor | Move.
    • Press F6.
    • Press Ctrl + Shift + R, and then select Move.
  3. If you selected the inner type, the following dialog box opens.

    Select the Another type option, and click Continue.

    Note    If you select the Outer Scope option, you will perform the Move Type to Outer Scope refactoring.
  4. If you selected static field or method (or if you chose to move inner type to another type), the following dialog box opens.

     

    The dialog box displays all static members of the class. You can select check boxes next to the items you want to move.

    Tip    If the refactored static member uses another static member of the same class, ReSharper highlights the used member with the blue color and shows a corresponding tooltip (for example, the myText field on the screenshot above).
  5. Type or browse for the name of the destination class. In the latter case, you can search for a type in a devoted dialog box that allows you to find a type by name (the Search tab) or select the type from the hierarchical tree (the Tree Tab).

  6. Select check boxes next to members you want to move. Note that you can move several static class members at once.
  7. Select the option corresponding to the required access right or left it "as is".
  8. Click Continue.

If no conflicts are found, the names and references are updated immediately.

See Also

Refactoring Code