Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 506
Nick Udell Avatar asked Aug 28 '14 14:08

Nick Udell


People also ask

What is inline method refactoring?

Inline Method refactoring 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.

What are refactoring techniques?

There are so many ways to refactor the code and simplify the logic. Some of them are: consolidate conditional expression and duplicate conditional fragments, decompose conditional, replace conditional with polymorphism, remove control flag, replace nested conditional with guard clauses, etc.

What is Extract method in VS code?

Extract Method Select the source code you'd like to extract and then click on the lightbulb in the gutter or press (Ctrl+.) to see available refactorings. Source code fragments can be extracted into a new method, or into a new function at various different scopes.

What is Move method?

Move Method Refactoring (MMR) refers to moving a method from one class to the class in which the method is used the most often. Manually inspecting and analyzing the source code of the system under consideration to determine the methods in need of MMR is a costly and time-consuming process.


1 Answers

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.

like image 58
Tanuj Mathur Avatar answered Jan 01 '23 12:01

Tanuj Mathur