The Inline Field refactoring replaces a field with its value and removes the declaration of the field. This refactoring works only for fields that have a single write usage.
- Place the caret at a field that has exactly one write usage (why it is so?).
Do one of the following:
- On the main menu, choose ReSharper| Refactor | Inline.
- Choose Refactor | Inline on the context menu.
- Press Ctrl+Shift+R, then click Inline Field.
- Press Ctrl+Alt+N.
If the selected field has more than one write usage, ReSharper reports a conflict.
Otherwise, ReSharper inlines the field immediately.
NoteIf there are several usages of the field within a method, ReSharper creates a local variable and replaces all them with the variable.
Consider the example below:
After applying the refactoring, the read usage of the ourKey field is replaced with initializing expression.