Convert to Auto-implemented Property
- 2 min to read
Converts a property with fully described accessors to an auto-implemented property. This removes the redundancy and makes the code clearer.
This Refactoring is opposite to Convert to Property with Backing Field.
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.
Place the caret on a property declaration statement.
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.
This feature is available as a part of Code Cleanup.