ReSharper will help you generate properties for all members that you want to expose.
You can set up common code generation options in the ReSharper | Options | Code Editing | Members Generation.
- Position the caret within a type where you would like to generate properties.
- On the main menu, choose ReSharper | Edit | Generate Code, or press Alt+Insert.
- In the Generate pop-up menu, select Properties or Read-only properties.
Generate dialog box that appears, select fields to generate properties for.
Optionally, use the following controls that are applied to all properties at this point
(see next step for guidelines on customizing individual properties):
- Access Rights defines common access rights for generated properties.
- Read-only defines whether to generate properties as read-only or not. If you choose Automatic, ReSharper will generate only getters for read-only fields, and both getters and setters for any other fields.
- Virtual (if applicable) adds the virtual modifier to generated properties.
- Notify on property changes (if applicable) If your class implements the INotifyPropertyChanged or inherits from a class that supports property change notifications (e.g., Prism’s NotificationObject), you can choose to implement properties with change notification calls.
Do one of the following:
To configure generation options (listed in the previous step)
individually for specific fields, click
You can then select individual fields, or
Ctrl-click two or more fields to configure
their respective settings in a uniform fashion.
After finishing this step, click Next, and as soon as the following screen appears, click Finish.
Finish to complete the wizard.
For example, if two fields are configured to be accessed with public read-only properties, and the other two are configured to be accessed with protected virtual read-write properties, the following code is generated:
- To configure generation options (listed in the previous step) individually for specific fields, click Advanced. You can then select individual fields, or Ctrl-click two or more fields to configure their respective settings in a uniform fashion.
You can convert any property with backing field to an auto-implemented property:
position the caret at the name of the property, press
Alt+Enter or click on the quick-fix icon, and then choose
Convert to auto-property in the
To bind any code generation command to its own shortcut, go to Tools | Options | Environment | Keyboard and look for commands starting with ReSharper_Generate.
This feature is supported in the following languages/technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see the corresponding topics in the ReSharper by Language section.
- Generating Type Constructors
- Implementing/Overriding Members
- Generating Delegating Members
- Generating Partial Methods
- Generating Equality Members
- Generating Equality Comparer
- Generating Formatting Members