Skip to main content

Property to Method(s)

  • 2 minutes to read
  • For read-only properties

    Converts the property into a method that returns a value, but does not have input parameters.

  • For write-only properties

    Converts the property into a method that has an input parameter and returns void.

  • For read-write properties

    Converts the property into two methods. Each method corresponds to a property accessor.

Property to Method(s) is a cascading refactoring. That is, the refactoring affects all property calls and property declarations in interfaces, base and descendant classes. For instance, if you apply the refactoring to the property declaration within an interface, it also changes the appropriate property declarations in all implementors and all calls to these properties.

#Availability

From the context menu or via shortcuts:

  • when the caret is on a property name within a property declaration.
  • when the caret is on a property call.

Note

The refactoring is available for property declarations in interfaces, base and descendant classes as well as for the declaration in the current class.

#Options

Using the Editor | Refactoring | Property to Method page in the Options dialog, you can specify where to declare methods, and which prefixes and visibility to use for them.

#Example

private object _TestProperty;
public object TestProperty
{
    get
    {
        return _TestProperty;
    }
    set
    {
        _TestProperty = value;
    }
}
Private _TestProperty As Object
Public Property TestProperty() As Object
    Get
        Return _TestProperty
    End Get
    Set(ByVal value As Object)
        _TestProperty = value
    End Set
End Property

Result:

private object _TestProperty;
public void SetTestProperty(object value)
{
    _TestProperty = value;
}
public object GetTestProperty()
{
    return _TestProperty;
}
Private _TestProperty As Object
Public Sub SetTestProperty(ByVal value As Object)
    _TestProperty = value
End Sub
Public Function GetTestProperty() As Object
    Return _TestProperty
End Function

#Animation

rsPropertyToMethods

See Also