ReSharper 2020.2 Help

Inline Method refactoring

ReSharper | Refactor | Inline | Inline…
Control+Alt+N
ReSharper_InlineVariable

This refactoring helps you replace usages of a static, instance, and extension method with its body, and optionally remove the original method declaration.
You can also apply this refactoring to a property with a backing field. In this case, read usages are replaced with the getter body and write usages are replaced with the setter body.

In the example below, we use this refactoring to inline the LogError method:

abstract class Shape { public void Draw() { try { /*draw*/ } catch (Exception e) { LogError(e); } } private static void LogError(Exception e) { File.WriteAllText(@"c:\Errors\Exception.txt", e.ToString()); } }
abstract class Shape { public void Draw() { try { /*draw*/ } catch (Exception e) { File.WriteAllText(@"c:\Errors\Exception.txt", e.ToString()); } } }

Inline a method

  1. Place the caret at the declaration or a usage of a method in the editor, or select it in the File Structure window.

  2. Do one of the following:

    • Press Control+Alt+N and then choose Inline Method

    • Press Control+Shift+R and then choose Inline Method

    • Right-click and choose Refactor | Inline Method in the context menu.

    • Choose ReSharper | Refactor | Inline | Inline… in the main menu.

    The Inline Method dialog will open.

  3. If you have invoked the refactoring at a method usage, you can clear the Inline all usages checkbox to inline only the current usage.

  4. Optionally, clear the Remove inlined method declaration checkbox to preserve the original method declaration.

  5. To apply the refactoring, click Next.

  6. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.

ReSharper: Inline Method dialog

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is available in Visual Basic .NETFeature is not available in C++Feature is not available in HTMLFeature is not available in ASP.NETFeature is not available in RazorFeature is not available in JavaScriptFeature is not available in TypeScriptFeature is not available in CSSFeature is not available in XMLFeature is not available in XAMLFeature is not available in Resource filesFeature is not available in build script filesFeature is not available in ProtobufFeature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

Last modified: 03 September 2020