Skip to main content

Expand Accessors (C#, C++)

Expands single-line getter or setter code onto multiple lines.

#Purpose

This refactoring is great if you plan to expand a property’s getter and setter bodies. With a single keystroke, you can reformat single-line accessor declarations into a multiple line format. This will make it easier to start modifications.

#Availability

Available from the context menus or via shortcuts:

  • when the caret is at the beginning of a property declaration statement. At least one of the accessors should have single-line declaration.

#Notes

  • This refactoring affects all accessors with single-line declarations.

#Example

private string _MyProperty;
public string MyProperty
{
    get { return _MyProperty; }
    set { _MyProperty = value; }
}

Result:

private string _MyProperty;
public string MyProperty
{
    get
    {
        return _MyProperty;
    }
    set
    {
        _MyProperty = value;
    }
}

#Screenshot

rsExpandAccessors

See Also