Convert Method to Indexer refactoring
This refactoring helps you convert methods that access collections into indexers and update method usages accordingly. You can apply it to:
A method with return value and one or more parameters to convert it into the
getaccessor of an indexer with the same set of parameters.
A method with
voidreturn type and two or more parameters (the last of which is expected to be a value and the others represent the index) to convert it into the
setaccessor of an indexer.
Consider the following example. If no indexer exists, the refactoring will create it:
If an indexer with only one of the accessors exists, the refactoring will try to add the second accessor if the converted method fits:
Convert a method into an indexer
Place the caret at the declaration or a usage of a method in the editor, or select it in the Structure window.
Do one of the following:
Press Ctrl+Alt+Shift+T and then choose Convert Method to Indexer
Choosein the main menu.
If no conflicts are found, JetBrains Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.