Invoking the Refactoring Tools

The refactoring tools are available directly inside the code editor. You can invoke them in several ways. First, if your cursor is positioned near code that Visual Studio thinks could or should be refactored, you will see a light bulb in the left margin of the code editor (called the Quick Actions menu). You can click on this to see your options unfold in a context-sensitive, refactoring menu. Second, you can always access Quick Actions from the editor using the shortcut “control dot” (Ctrl+.). A right-click inside your code will also take you to Quick Actions from the context menu. Finally, the Visual Studio class designer supports edits that work as refactoring.


Note

Visual Studio has done away with the Refactoring menu that used to appear at the top of the tool in favor of the Quick Actions menu directly inside the code editor.


Using the Quick Actions Menu

Figure 9.1 shows the Quick Actions menu being invoked via the keyboard shortcut (Ctrl+.) or a right-click on the method signature (and choosing Quick Actions from the context menu). Notice the light bulb on the left and the menu that unfolds. The options in the menu are context sensitive to actions you could take on the highlighted code. In this case, the only option is to change the method signature (reorder the parameters) within the selected constructor for the InvoiceLineItem class.

Image

FIGURE 9.1 Use Ctrl+. to access the Quick Actions menu to refactor your code.

Notice in Figure 9.1 that there is no preview of your possible changes. This is because the Change Signature refactor option has too many options, and it would be confusing to put all of them in the preview window. To finish invoking this refactor, click on the Change Signature menu item next to the light bulb. This brings up the Change Signature dialog as shown in Figure 9.2. From here you can chance the order of parameters (move up/down buttons with arrows) and remove parameters.

Image

FIGURE 9.2 Use the Change Signature dialog to modify your method signature.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset