7

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.
0

2 Answers 2

10
+50

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

You might consider collecting the functions into a header file and decorating them with inline. I realize this is not exactly an answer to what you asked, but may be a better solution to your problem because this way the compiler would perform the inlining (if it sees fit).

It depends on the situation, but keeping the function definitions might lead to clearer code, thus might be of value even if called only once.

This is also quicker and less error prone than manual "inline method" refactorings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.