Renaming Code

Renaming code elements is the most common Refactoring operation. Visual Studio supports Rename operations in Visual Basic, C#, C++, database schemas, and other code elements. Thankfully, all these Rename operations work in a similar fashion.

Most developers do not wait until the code base is operational and say to themselves, “Okay, now I will go back and rename items for clarity.” The more likely scenario is that as you build your application, you consistently rename items to correct mistakes or make things clearer and more readable. Of course, as the code base builds, it becomes more and more difficult to rename classes, methods, fields, and the like without introducing new bugs into your code.

The capability to rename items with the confidence that you are not introducing bugs into your code is paramount. With the Visual Studio editor, you can rename all relevant code items including namespaces, classes, fields, properties, methods, and variables. The compiler helps make sure that your code does not get broken and that all source code references are found. In fact, the Rename operation can even search through your code comments and strings and update them accordingly.


Tip

The 2015 version of Visual Basic and C# includes the keyword nameOf. (See Chapter 3, “The .NET Languages.”) You can use this expression to use actual types where you need to pass string literals. This gives you compile-time checking of Rename operations.


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

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