ReSharper 8.0 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:


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


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


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.