Extracting Methods

With the Extract Method operation, you can create (or extract) a new method from multiple lines of code, a single line, or an expression within a given line of code. In each case, the method is created immediately following the method from which the code was extracted. The extracted code is replaced by a call to the new method.

Listing 9.1 provides an example of a method (GetFullInvoice) that is unnecessarily long. We’ve added line numbers for reference purposes. When you’re reviewing code, methods such as these are common and exactly what you should be looking for. The method is designed as a static call that returns a given customer’s Invoice object based on the ID number. However, the invoice and the line items are all retrieved ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.