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
To convert a static method to an extension method
- Position the caret at the name of a static method that meets the above requirements, or select it in File Structure.
- Choose ReSharper | Refactor | Convert | Static to Extension Method.
- The refactoring will be carried out without requiring you to specify any further options.
Consider the following method declaration:
and its usage:
After converting it to an extension method, its signature will receive an additional this parameter:
and it will be called like a common instance method:
