Auto-implemented properties (also known auto-properties) allow declaring type properties that do not have additional logic in a simpler way. By default, ReSharper encourages using of auto-properties when possible, but this behavior is configurable.
If you do not want ReSharper to suggest you this, you can change the severity level of the code inspection that detects it (Convert property to auto-property) to Do not show. 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:
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 compound property context action:
Another option to convert properties to auto-properties in a bulk mode is code cleanup. You can either run code cleanup with the default profile Default: Full Cleanup or run the cleanup with a custom profile solely targeted at your specific task as described below.
To convert properties to auto-properties with code cleanup
- Open the Code Cleanup options: .
- Create a new profile as described in the Configuring Code Cleanup section. In the Selected profile settings section for the new profile tick the Use auto-property, if possible check box.
- Click Save to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.
- Select the scope where you want to use auto-properties:
- Do one of the following:
- In the Code Cleanup Dialog that opens, select the newly created profile in the Available Profiles area.
- Click Run. ReSharper will use auto-properties in the selected scope.
If you want to convert properties to auto-properties without opening the Code Cleanup Dialog, you can bind the created profile to the silent cleanup and run it simply by pressing Ctrl+Shift+Alt+F. You can also create a custom cleanup profile that would combine converting to auto-properties with other code style tasks.
This feature is supported in the following languages/technologies:
- Naming Style
- Navigating between Code Issues
- Finding Out What is Wrong with Your Code
- Code Formatting Rules
- File and Type Layout
- File Header Style
- Namespace Imports Assistance
- Implicit/Explicit Typing
- Using Auto-Properties
- Making Fields Readonly
- Attributes Style
- Arranging Modifiers
- Arranging Optional Member Qualifiers
- Reformatting XML Doc Comments
- Removing Code Redundancies