JetBrains Rider 2017.2 Help

Inline Method refactoring

Ctrl+R, I

This refactoring helps you replaces 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:

Before refactoringAfter refactoring
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()); } } }

To inline a method

  1. Place the caret at the declaration or a usage of a method in the editor, or select it in the Structure window.
  2. Do one of the following:
    • Press Ctrl+R, I and then choose Inline Method
    • Press Ctrl+Shift+R and then choose Inline Method
    • Choose Refactor | Inline Method 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 check box to inline only the current usage.
  4. Optionally, clear the Remove inlined method declaration check box to preserve the original method declaration.
  5. To apply the refactoring, click Next.
  6. If no conflicts are found, JetBrains Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
Refactorings Inline Method dialog box
Last modified: 23 November 2017

See Also