ReSharper Help  

Convert Property to Method(s)

The Convert Property to Method(s) refactoring allows users to convert type properties to getter and/or setter methods. Namely, each read property is converted to a getter method, each write property is converted to a setter method, and each read-write property is converted to two separate methods: a getter and a setter.

To change a property to setter/getter method(s), right-click the mouse on the name of the property in Class View, Object Browser, or in the editor, and select Refactor | Convert Property to Method(s) from the appearing popup menu.

The following dialog will appear:

Note   The dialog shown appears when you try to convert a read-write property to method(s). For read properties, setter-related fields are disabled. Similarly, for write properties, getter-related fields are disabled.

For a read-write property you can generate a pair of getter-setter methods - or either of them - by selecting the appropriate checkboxes. You also have the possibility to change the default method names suggested by ReSharper.

Press OK, and the selected property will be changed to getter/setter method(s). At the same time, all usages of the property (both read and write) will be substituted with the corresponding method calls.

Consider the following example:

After we have changed the property X to a pair of getter/setter methods the code looks as follows:

See Also

Refactoring Code | Convert Method to Property