The Convert Method to Property refactoring converts methods with return values and without parameters to read properties, and methods with void return type and exactly one parameter to write properties.
- Place the caret at the name of a method in the editor, in the File Structure window, in Class View or in Object Browser.
Do one of the following:
- On the main menu, choose ReSharper | Refactor | Convert | Method to Property.
- Choose Refactor | Convert | Method to Property on the context menu.
- Press Ctrl+Shift+RCtrl+Shift+R and click Convert Method to Property.
The Convert Method to Property dialog box opens.
Type a property name into the Property name text box or leave the
- Click Next. If no conflicts are found, ReSharper performs the refactoring immediately and changes the method to a read or a write property. At the same time, all method calls are substituted with the corresponding property accesses. Otherwise, resolve conflicts.
Consider the example below:
After applying the refactoring, the SetBackgroundColor method is replaced with the BackgroundColor property:
This feature is supported in the following languages/technologies:
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.