This refactoring converts a static method to an extension method, given that the static method:
- Has at least one argument.
- Resides in a static class.
The refactoring works in dialogless mode.
The reverse functionality is available with the Convert Extension Method to Plain Static refactoring.
- Place the caret at the name of a static method that meets the above requirements, or select it in the File Structure window, in Object Browser or in Class View.
Do one of the following:
- On the main menu, choose ReSharper | Refactor | Convert | Static to Extension Method.
- Choose Refactor | Convert | Static to Extension Method on the context menu.
- Press Ctrl+Shift+RCtrl+Shift+R, then click Convert Static to Extension Method.
- The refactoring is carried out without requiring you to specify any further options.
Take a look at the following method declaration:
and its usage:
After converting it to an extension method, an additional this parameter is added to the signature:
and it is called like a common instance 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.