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+RCtrl+Shift+R, then click Inline Field.
- Press Ctrl+Alt+NCtrl+R,I.
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.
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.