The Inline Method refactoring replaces the usages of a method with its body and optionally removes the original method declaration. Static, instance and extension methods are all supported.
TipThis refactoring also works with properties.
The reverse functionality is provided by the Extract Method refactoring.
- Place the caret at a method declaration or method call to inline, or select a method declaration in the File Structure window.
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 Method.
- Press Ctrl+Alt+NCtrl+R,I.
The Inline Method dialog box opens.
- Select the Inline all usages check box to inline all usages of the method. Otherwise, ReSharper replaces only the usage where the caret is.
- Select the Remove inlined method declaration check box to remove the original method declaration. Otherwise, ReSharper leaves it as is.
- Click Next. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, resolve conflicts.
NoteReSharper displays a warning if you attempt to inline a method that has no usages, such as a Main() method.
Consider the example below:
After applying the refactoring, the ProcessAssemblyMetadata method call is replaced with its body.
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.