Convert Property to Auto-Property refactoring
This refactoring helps you convert properties with private backing fields into auto-implemented properties (also known as auto-properties). The refactoring removes the backing field and replaces all its usages with the newly created auto-property.
By default, JetBrains Rider highlights most of the properties that could be converted to auto-properties and suggests the corresponding quick-fix or fix in scope:
![Use auto-property quick-fix Use auto-property quick-fix](https://resources.jetbrains.com.cn/help/img/rider/2024.2/auto_property_fix.png)
If you do not want JetBrains Rider to suggest this, you can disable the code inspection that detects it (Convert property to auto-property). In this case, properties with backing fields are not highlighted and quick-fixes are not suggested, but you can still apply the conversion with the context action or with the corresponding refactoring:
![To auto-property context action To auto-property context action](https://resources.jetbrains.com.cn/help/img/rider/2024.2/auto_property_ca.png)
The reverse functionality of converting existing auto-properties to properties with backing field is also available with the corresponding context action. You can also generate default bodies for property accessors using the To computed property context action:
![To property with backing field context action To property with backing field context action](https://resources.jetbrains.com.cn/help/img/rider/2024.2/auto_property_ca_2.png)
In the example below, the refactoring converts a property with a backing field to an auto-property:
You can also convert properties to auto-properties using the refactoring commands. To do so, place the caret at the declaration or a usage of a property in the editor, or select it in the Structure window window, and then do one of the following:
Press Ctrl+Alt+Shift+T and then choose Convert Property to Auto-property
Right-click and choose Refactor | Convert Property to Auto-property in the context menu.