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

See Also