Refactoring

Refactoring is the process of improving your code after it has been written by changing the internal structure of the code without changing the external behavior of the code.

Visual C# provides the following refactoring commands on the Refactoring menu:

Multi-Project Refactoring

Visual Studio supports multi-project refactoring for projects that are in the same solution. All of the refactoring operations that correct references across files correct those references across all projects of the same language. This works for any project-to-project references. For example, if you have a console application that references a class library, when you rename a class library type (using the Rename refactoring operation), the references to the class library type in the console application are also updated.

Preview Changes Dialog Box

Many refactoring operations provide an opportunity for you to review all the reference changes that a refactoring operation would perform on your code, before committing to those changes. For these refactoring operations, a preview reference changes option will appear in the refactoring dialog box. After selecting that option and accepting the refactoring operation, the Preview Changes Dialog Box will appear. Notice that the Preview Changes dialog box has two views. The bottom view will display your code with all the reference updates due to the refactoring operation. Pressing Cancel on the Preview Changes dialog box will stop the refactoring operation, and no changes will be made to your code.

Error-Tolerant Refactoring

Refactoring is error tolerant. In other words, you can perform a refactoring in a project that cannot build. However, in these cases the refactoring process might not update ambiguous references correctly.

See Also

Tasks

How to: Restore C# Refactoring Snippets

Other Resources

Visual C# Code Editor Features