Convert to Auto-implemented Property
- 2 minutes to read
Purpose
Converts a property with fully described accessors to an auto-implemented property. This removes the redundancy and makes the code clearer.
NOTE
This Refactoring is opposite to Convert to Property with Backing Field.
Availability
Available when the caret is on a property declaration statement. The property should have a getter that does nothing but return a field value and a setter that only assigns that field a value.
Usage
Place the caret on a property declaration statement.
NOTE
The blinking cursor shows the caret's position at which the Refactoring is available.
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- Select Convert to Auto-implemented Property (Convert to Auto-implemented Property (convert all) to convert all properties in the active type) from the menu.
After execution, the Refactoring removes the intermediate private variable along with the getter and setter bodies.
NOTE
This feature is available as a part of Code Cleanup.
See Also