ReSharper Web Help

Use this refactoring to convert:

  • Get accessor of an indexer (default property in VB.NET) to a method with return value and a set of parameters that match those of the original indexer.
  • Set accessor of an indexer, if any, to a void method with a set of indexer parameters and a value parameter.
Usages of indexers will be converted accordingly to call those methods.

The reverse functionality is provided by the Convert Method to Indexer (Default Property) refactoring.

To convert an indexer (default property) to a method
  1. In the editor, place the caret at an indexer that you'd like to convert.
  2. On the ReSharper menu or context menu, choose Refactor | Convert | Indexer to Method. The Convert Indexer to Method dialog box displays:
  3. Use Convert getter and Convert setter check boxes to choose which accessors to convert, and specify target method names in Getter name and Setter name fields.
  4. Click Next to apply the refactoring.

Consider the following example:

Before:
public string this[short number]
    {
      get
      {
        string projectId;
        if (myDictionary.TryGetValue(number, out projectId))
          return projectId;
        else
          return null;
      }

      set
      {
        myDictionary.Add(number, value);
      }
    }
After:
public void SetItem(short number, string value)
    {
       myDictionary.Add(number, value);
    }

public string GetItem(short number)
    {
       string projectId;
          if (myDictionary.TryGetValue(number, out projectId))
                  return projectId;
          else
                  return null;
    }

See Also

Procedures