The Make Method/Property Static refactoring allows you to convert an instance method or a property to a static one. All calls, implementations and overrides of the method/property are automatically corrected.
When you are making a method static, you can choose to add parameters to it from the list of class members referenced in its body. Reverse functionality is available with the Make Method/Property Non-Static refactoring.
- Place the caret at the name of a method or property in the editor.
Do one of the following:
- On the main menu, choose ReSharper | Refactor | Make Method Static.
- Right-click, then click Refactor | Make Method Static on the context menu.
- Press Ctrl+Shift+RCtrl+Shift+R, then click Make Method Static.
The Make Static dialog box opens.
Click one of the following:
- Do not add parameters to the method
- Add 'this' as parameter of [type name] to add a parameter with the enclosing type and type a new name in the Parameter name text box or leave the default one.
- Introduce parameters from following expressions to add a separate parameter for each expression. In the list below, select the necessary expressions to add them as parameters.
- Click Next. If no conflicts are found, the refactoring is performed immediately. Otherwise, resolve conflicts.
Consider the example below:
After applying the refactoring, the method is made static, mySubmitter and mySettings fields are now passed as parameters to the method.
This feature is supported in the following languages/technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see the corresponding topics in the ReSharper by Language section.