ReSharper Help  

Convert Method to Property

The Convert Method to Property refactoring allows users to convert non-void methods without parameters to read properties, and void methods with exactly one parameter to write properties.

To change a suitable method to a read or write property, right-click on the name of the method in Class View, Object Browser, or in the code editor, and select Refactor | Convert Method to Property from the popup menu.

The following dialog appears allowing you to change the default property name suggested by ReSharper:

Click  OK to change the selected method to a read or a write property. At the same time, all method calls will be substituted with the corresponding property accesses.

Consider the following example:

After we have changed the method setX to a write property X the code looks as follows:

If you try to apply the Convert Method to Property refactoring to a method that cannot be converted to a property, the following error message is displayed:

See Also

Refactoring Code | Convert Property to Method(s)