ReSharper Web Help

This refactoring serves the opposite purpose to Convert Indexer (Default Property) to Method. So, it converts:

  • A method with return value and a set of parameters to get accessor of an indexer with the same set of parameters.
  • A method with a void return type, a set of indexer parameters and a value parameter to set accessor of an indexer.
Method calls are converted to indexer usages accordingly.

To convert a method to an indexer
  1. Place the caret at the name of a method in the editor, 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 | Method to Indexer.
    • Choose Refactor | Convert | Method to Indexer on the context menu.
    • Press Ctrl+Shift+RCtrl+Shift+R and click Convert Method to Indexer.
  3. If no conflicts are found, ReSharper performs the refactoring immediately and the selected method is converted in dialogless mode. Otherwise, resolve conflicts.

Consider the example below:

Refactorings__Convert_Method_to_Indexer_01

So the SetMetadata method with a void return type is converted into an indexer with a set accessor.

Refactorings__Convert_Method_to_Indexer_02


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.