Declare Property (with backing store)

Declares a property with a backing store for the current reference to an undeclared element. Places the cursor on the generated property declaration and drops a marker onto the initial property reference.

Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on an undeclared element reference.

Notes

  • If the code provider is called for an element contained in the right part of an expression, a read-only property will be generated. Otherwise, the provider will declare a read-write property. To add a setter to a read-only property, use the Declare Setter code provider.

Example

private int TestMethod()
{
    return MyProp + 15;
}
Private Function TestMethod() As Integer
    Return MyProp + 15
End Function

Result:

private int _MyProp;
public int MyProp
{
    get
    {
        return _MyProp;
    }
}
private int TestMethod()
{
    return MyProp + 15;
}
Private _myProp As Integer
Public ReadOnly Property MyProp() As Integer
    Get
        Return _myProp
    End Get
End Property
Private Function TestMethod() As Integer
    Return MyProp + 15
End Function