Convert to Auto-Implemented Property
- 2 minutes 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 the opposite of the Convert to Property with Backing Field refactoring.
This refactoring is available when the caret is in a property declaration statement. A property should have a getter that does nothing but return a field’s value, and a setter that assigns a value to this field.
Place the caret in a property declaration statement.
The blinking cursor shows the caret’s position at which the Refactoring is available.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
Select Convert to Auto-Implemented Property from the menu.
You can also use the Convert All Properties to Auto-Implemented refactoring to convert all properties in the active type.
After execution, this refactoring removes the intermediate private variable along with the getter and setter bodies.
CodeRush can convert not-implemented properties to auto-implemented properties. For more information, refer to the following topic: Code Actions Settings.
You can also apply the “Make properties auto-implemented” rule in code cleanup. See the following topic for more information: Configure Cleanup.