ReSharper 2020.3 Help

Convert Property to Auto-Property refactoring

ReSharper | Refactor | Convert | Property to Auto Property…
ReSharper_Property2Auto

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, ReSharper 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

If you do not want ReSharper 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

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

In the example below, the refactoring converts a property with a backing field to an auto-property:

class Shape { private Color bgColor; public Color BackgroundColor { get { return bgColor; } set { bgColor = value; } } public Shape(Color background) { bgColor = background; } }
class Shape { public Color BackgroundColor { get; set; } public Shape(Color background) { BackgroundColor = background; } }

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 File Structure window, and then do one of the following:

  • Press Control+Shift+R and then choose Convert Property to Auto-property

  • Right-click and choose Refactor | Convert Property to Auto-property in the context menu.

  • Choose ReSharper | Refactor | Convert | Property to Auto Property… in the main menu.

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is available in Visual Basic .NET Feature is not available in C++ Feature is not available in HTML Feature is not available in ASP.NET Feature is not available in Razor Feature is not available in JavaScript Feature is not available in TypeScript Feature is not available in CSS Feature is not available in XML Feature is not available in XAML Feature is not available in Resource files Feature is not available in build script files Feature is not available in Protobuf Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

Last modified: 08 March 2021