Search code examples
visual-studio-2013refactoringautomated-refactoringinlining

Opposite of Extract Method refactoring


Is there a way to perform the opposite of the "Extract Method" refactor in Visual Studio?

I have a legacy codebase that has ~50 very short, private functions that are only used once each, and I have been tasked with inlining them.

If an automatic inline refactoring isn't possible, is it possible to reduce the amount of time it takes to inline these function calls? My current workflow is:

  • Copy the code in the function.
  • Find where it is called.
  • Replace the function call with the copied code.
  • Replace local variable names from the function.
  • Delete the function.

Solution

  • The refactoring you are looking for is called "Inline Method".

    While Visual Studio does not provide this refactoring out of the box, you can get access to it (and many other useful refactorings) by installing the Jetbrains ReSharper extension for Visual Studio.

    With the extension installed, all you need to do is click on the method declaration or method call, and invoke the 'Inline Method' refactoring. This will automatically inline all occurrences of the method and delete it.