Home > Refactorings > Refactorings – Inline Method

Refactorings – Inline Method

February 17th, 2011

The Inline Method refactoring lets you move the method’s body into the body of its callers and remove the method declaration, if needed. Inline Method is helpful when you have a group of methods that seem badly factored. You can inline them all into one big method, and then re-extract the methods.

Another reason to use Inline Method is that sometimes you do come across a method in which the body is as clear as the name. Or, you refactor the body of the code into something that is just as clear as the name. When this happens, you should then get rid of the method.

There are two versions of this refactoring:

  • Inline Method
  • Inline Method (and delete)

The difference between the two is that the second one removes the source method, if appropriate.

The refactoring is available either on the source method name or the calling side.

Opposite

The opposite of this refactoring is the Extract Method refactoring.

Source sample code

Refactor! Inline Method source code CS

Show Visual Basic: »

Refactor! Inline Method source code VB

Refactoring preview

Refactor! Inline Method preview CS

Show Visual Basic: »

Refactor! Inline Method preview VB

Result

Refactor! Inline Method result CS

Show Visual Basic: »

Refactor! Inline Method result VB

Please note the Version field below for this refactoring.

—–
Products: Refactor! Pro
Versions: 2011.1 and up
VS IDEs: any
Updated: Feb/17/2011
ID: R021

Similar Posts: