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+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: