ReSharper 8.0 Web Help

The Convert Method to Property refactoring converts methods with return values and without parameters to read properties, and methods with void return type and exactly one parameter to write properties.

To change a method to a read or write property
  1. Place the caret at the name of a method in the editor, in the File Structure window, in Class View or in Object Browser.
  2. Do one of the following:
    • On the main menu, choose ReSharper | Refactor | Convert | Method to Property.
    • Choose Refactor | Convert | Method to Property on the context menu.
    • Press Ctrl+Shift+RCtrl+Shift+R and click Convert Method to Property.
  3. The Convert Method to Property dialog box opens. Type a property name into the Property name text box or leave the default one:

    Refactorings__Convert_Method_to_Property__dialog_box

  4. Click Next. If no conflicts are found, ReSharper performs the refactoring immediately and changes the method to a read or a write property. At the same time, all method calls are substituted with the corresponding property accesses. Otherwise, resolve conflicts.

Consider the example below:

Refactorings__Convert_Method_to_Property_01

After applying the refactoring, the SetBackgroundColor method is replaced with the BackgroundColor property:

Refactorings__Convert_Method_to_Property_02


This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available

Tip

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