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
get
accessor of an indexer with the same set of parameters. -
A method with
void
return 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 theset
accessor of an indexer.
Consider the following example:
To convert a method to an indexer
- Place the caret at the declaration or a usage of a method in the editor, or select it in the File Structure Window.
- Do one of the following:
- If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
This feature is supported in the following languages/technologies:
C# | VB.NET | C++ | HTML | ASPX | Razor | JavaScript | TypeScript | CSS | XML | XAML | RESX | Build Scripts | Protobuf | JSON |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.
See Also
Last modified: 15 December 2016