Making (and Previewing) Changes

As you become comfortable with the refactoring tools, you might decide to simply let them do their thing without much oversight on your part. However, if you are like most developers, no one (or no tool) touches your code without your consent. Fortunately for us, the refactoring tools provide a preview option. This option lets you follow the tool through its changes and, in turn, accept or reject a given change. It also supports Undo should you want to revert your changes.

The Preview Changes dialog box is invoked as an option (check box) on a given Refactoring operation. Figure 9.3 shows an example of invoking the Rename operation from the context menu (right-click). In this case, we are renaming the InvoiceLineItems class. Notice the option to preview changes.

Image

FIGURE 9.3 A Rename operation with Preview Changes selected.

To complete this refactor, you first rename the class inside the code editor. You then click Apply on the small Rename dialog shown in Figure 9.3 (upper right). Provided you have enabled Preview Changes, Visual Studio will open the Preview Changes dialog, as shown in Figure 9.4. The top portion of this dialog box lists all the changes that the given Refactor operation intends to make. This list is presented as a tree, with the outer branch representing where you intend to originate the change. All the leaves under this branch are files where changes happen. Nested beneath the filenames are the actual places within the code where a change is made. You use this list to select each item you would like to preview. You can review each change, select/unselect those to apply, and ultimately apply changes to your code (or cancel the operation).

Image

FIGURE 9.4 Previewing the changes of a Rename operation.

As each item in the Preview Changes tree is clicked, the corresponding code is displayed below the tree in the Preview Code Changes section of the dialog box. This enables developers to quickly review where changes are being made. To prevent a given change, you can simply uncheck the item in the tree view. Of course, you can prevent entire file changes by unchecking further up in the hierarchy at the file level. When you are finished with your preview and satisfied with the proposed changes, you simply click the Apply button to commit the changes to your code.

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

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