Skip to main content

Collapse Setter (C#, C++)

Collapses simple setter code onto a single line.

#Purpose

This refactoring is great for making your code more compact. With a single keystroke, you can convert a single-statement setter declaration to a single-line form.

#Availability

Available from the context menus or via shortcuts:

  • when the caret is within a setter declaration. The setter should consist of a single statement.

#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

rsCollapseGetter

See Also