ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Convert Method to Property refactoring

Last modified: 21 July 2022

ReSharper | Refactor | Convert | Method to Property…

To assign a shortcut, go to Tools | Options | Environment | Keyboard and find the ReSharper_Function2Property command.

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 set accessor.

Consider the following example:

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:

ReSharper refactorings: Convert method to property dialog

This feature is supported in the following languages and technologies:

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by language section.