Convert Method to Property refactoring
This refactoring helps you convert methods with return values and without parameters to properties with the corresponding
get accessor, and methods with
void return type and exactly one parameter to properties with the corresponding
If there is an existing property with a single accessor and the converted method has compatible parameter type or return type, the refactoring can add the second accessor to the existing property.
Consider the following example:
|Before refactoring||Applied to 'GetFaculty'||Then applied to 'SetFaculty'|
| || || |
To convert a method to a property
- Place the caret at the declaration or a usage of a method in the editor, or select it in the Structure window.
- Do one of the following:
- Press Ctrl+Shift+R and then choose Convert Method to Property
- Choose in the main menu.
- Type the name for the property name leave the default suggestion. You can type the name of an existing property with a single accessor if the converted method will fit as the second accessor.
- To apply the refactoring, click Next.
- If no conflicts are found, JetBrains Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.