Back to Devexpress

Convert to Property with Backing Field

coderushforroslyn-115953-refactoring-assistance-convert-to-property-with-backing-field.md

latest1.6 KB
Original Source

Convert to Property with Backing Field

  • Aug 03, 2020

Purpose

Converts an auto-implemented property to a property with the private field and fully described accessors. This prepares the property for the extension.

Note

This Refactoring is opposite to Convert to Auto-implemented Property.

Availability

Available when the caret is on a property declaration statement. The property should be auto-implemented.

Usage

  1. Place the caret on a property declaration statement.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Convert to Property with Backing Field from the menu.

After execution, the Refactoring adds the intermediate private variable along with the getter and setter bodies.

csharp
string a;
public string A {
    get {
        return a;
    }
    set {
        a = value;
    }
}
vb
Private _a As String
Public Property A() As String
    Get
        Return _a
    End Get
    Set(ByVal value As String)
        _a = value
    End Set
End Property

See Also

Convert to Auto-Implemented Property

Collapse/Expand Property

Add Getter/Setter

Use Expression Body