Collapse Accessors (C#, C++)
In This Article
Collapses simple getter or setter code onto a single line.
#Purpose
This refactoring is great for making property declarations more compact. With a single keystroke, you can reformat a property’s one-statement accessors to a single-line form.
#Availability
Available from the context menus or via shortcuts:
- when the caret is at the beginning on declaration of a setter or getter that contains a single statement.
#Notes
- This refactoring affects all single-statement accessors within a property.
#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
See Also