ReSharper 8.0 Web Help

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.

To convert a static method to an extension method
  1. 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.
  2. 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.
  3. The refactoring is carried out without requiring you to specify any further options.

Take a look at the following method declaration:

Refactorings__Convert_Static_to_Extension_Method__before__declaration

and its usage:

Refactorings__Convert_Static_to_Extension_Method__before__usage

After converting it to an extension method, an additional this parameter is added to the signature:

Refactorings__Convert_Static_to_Extension_Method__after__declaration

and it is called like a common instance method:

Refactorings__Convert_Static_to_Extension_Method__after__usage


This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available

Tip

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.