ReSharper Web Help

The Introduce Field refactoring allows users to quickly create a new field based on a selected expression, initialize it with the expression, and replace occurrences of the expression in the code with references to the newly introduced field.

To introduce a field
  1. Select an expression in the editor.
  2. 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:
    Introduce Field refactoring
  3. Choose whether to replace:
    • Only the selected occurrence.
    • All occurrences of the expression.
    • All occurrences within the current member.
    The Introduce Field dialog box opens:
    Introduce Field refactoring
  4. Specify a name for the new field.
  5. Select an option in the Introduce field and initialize in section:
    • 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.
  6. In the Visibility group, select the visibility of the new field.
  7. Optionally, select Make static and Make field read-only check boxes.
  8. Click 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.

See Also