ReSharper Help  

Make Method Static

The Make Method Static refactoring allows you to convert an instance method to a static one. All calls, implementations and overridings of the method are automatically corrected. While making the method static you can choose to add parameters to it from the list of class members referenced in its body.

The reverse functionality is also possible with the Make Method Non-Static refactoring.

To make a method static

  1. Place the caret at the method name in the editor. Example:

  2. Do one of the following:
    • In the main menu, click ReSharper | Refactor | Make Method Static.
    • Right-click the method name, and select Refactor | Make Method Static in the shortcut menu.
    • Press Ctrl + Shift + R, and then select Make Method Static.

    The Make Method Static dialog opens:

  3. If any class members are referenced in the body of the method, you have the choice to add parameter(s) to the new static method signature. You can do either or both of these:
    • Add 'this' as parameter - the current class will be added. You must select a name for the parameter (type your own or select from the list of suggestions);
    • Add parameters for fields - in the list below, select the necessary fields to add them as parameters (see example below). Optionally, type in the new parameter names in the Parameter Name box for each field.

    Click Move Up or Move Down to change the order of the new parameters.

  4. Click Continue . If no conflicts are found, the refactoring is performed immediately. Example (continued from above):

See Also

Refactoring Code