Skip to main content

Declare Property

Declares a property for the current reference to an undeclared element. Selects the property getter or setter contents and drops a marker onto the initial property reference. To choose the property declaration position, use the Target Picker.

#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:

public int MyProp
{
    get
    {throw new NotImplementedException();
    }
}
private int TestMethod()
{
    return MyProp + 15;
}
Public ReadOnly Property MyProp() As Integer
    GetThrow New NotImplementedException()
    End Get
End Property
Private Function TestMethod() As Integer
    Return MyProp + 15
End Function