ReSharper will help you generate properties for all fields that you want to expose.
In the example below, this command is used to generate properties for
To generate properties that will expose selected fields
- In the editor, set the caret on the type name or within a type at the line where you want to insert properties that will expose selected fields. If the caret is on the type name, generated code will be added in the beginning of the type declaration.
- In the Generate dialog that appears, select fields to generate properties for.
Optionally, use the following controls that are applied to all generated properties:
- Access Rights defines access rights modifiers for generated properties.
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.
If you have selected Read-only Properties in the Generate pop-up, the selector is set to Yes, but you can change it if necessary.
(if applicable) adds the
virtualmodifier to generated properties.
Notify on property changes
If your class implements the
INotifyPropertyChangedor inherits from a class that supports property change notifications (e.g., Prism’s
NotificationObject) and the method that notify property change is decorated with the [NotifyPropertyChangedInvocator] attribute, you can choose to implement properties with change notification calls. For more information, see INotifyPropertyChanged Support.
to complete the wizard.
You can also click Options to review or modify common code generation preferences on the page of ReSharper options.
This command generate properties leaving the original fields intact. If necessary, you can convert the generated properties to auto-implemented properties by pressing Alt+Enter on any of the properties:
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 corresponding topics in the ReSharper by Language section.