To introduce a field
- Select an expression in the editor.
On the ReSharper menu or context menu, choose
Refactor | Introduce Field, or press Ctrl+Alt+D. If more than one occurrence of the selected expression is found, ReSharper displays the following drop-down menu:
Choose whether to replace:
- Only the selected occurrence.
- All occurrences of the expression.
- All occurrences within the current member.
Introduce Fielddialog box opens:
- Specify a name for the new field.
- Select an option in the
Introduce field and initialize insection:
Current member: initializes the field in the current member (this option is only available if you chose to replace a single occurrence or occurrences within the current member).
Field initializer: initializes the field right where it is declared.
Constructor(s): initializes the field in the constructor or constructors of the containing class; if necessary, creates a parameterless constructor and initializes the field from within it.
Introduce constant: creates a constant instead of a field.
Visibilitygroup, select the visibility of the new field.
- Optionally, select
Make staticand Make field read-onlycheck boxes.
Next. The new field will be created and initialized according to specified settings. One or more occurrences of the selected expression will be replaced by usages of the new field.