As opposed to refactoring an extract method

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

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

If automatic inline refactoring is not possible, can you reduce the time it takes to inline these function calls? My current workflow:

  • Copy code to function.
  • Find where it's called.
  • Replace the function call with the copied code.
  • Replace local variable names from function.
  • Remove function.
+3


source to share


2 answers


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

.

While Visual Studio doesn't provide this refactoring out of the box, you can access it (and many other useful refactorings) by installing Jetbrains ReSharper for Visual Studio.



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

+5


source


You might want to pack the functions into a header file and decorate them with inline

. I understand that this is not exactly the answer to what you asked, but it might be a better solution to your problem, because that way the compiler would inlining (if it deems it necessary).

It depends on the situation, but keeping function definitions can lead to cleaner code, so it can make a difference even if called only once.



It is also faster and less error prone than manual "inline method" refactorings.

-1


source







All Articles