ReSharper Web Help

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.

To inline a field
  1. Place the caret at a field that has exactly one write usage (why it is so?).
  2. 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.
  3. If the selected field has more than one write usage, ReSharper reports a conflict. Otherwise, ReSharper inlines the field immediately.

    Note

    If 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:

Refactorings__Inline_Field_01

After applying the refactoring, the read usage of the ourKey field is replaced with initializing expression.

Refactorings__Inline_Field_02


This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available

Tip

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.