The Convert Property to Method(s) refactoring converts 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.
- Place the caret at the name of a property in the editor, in the File Structure window, in Class View or Object Browser.
- Do one of the following:
- On the main menu, choose ReSharper| Refactor | Convert | Property to Method(s).
- Press Ctrl+Shift+R, then click Convert Property to Method(s).
- The Convert Property to Method(s) dialog opens. Type method
names in the appropriate boxes or leave the default ones:
NoteFor a read-write property you may generate a pair of methods, or a single method for either getter or setter, by leaving the appropriate check box selected.
- Click Next. The property is converted into appropriate 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 example below:
After converting the
property into a pair of methods, the code looks as follows: