Refactoring – a new feature in the Visual C# 2.0 IDE
CoderSource.net
Refactoring – a new feature in the Visual C# 2.0 IDE - Article by muskad202
Level: BeginnerType: Article
Rating: Page: 1 of 4

Date: 4/23/2006 12:00:00 AM

Environment: Windows, Visual Studio .Net 2005

Refactoring – a new feature in the Visual C# 2.0 IDE


Renaming variables:

Assume you have a solution containing about 25 classes (we’ll also assume that each class is in a separate source file – that means 25 .cs files).

Suppose one class has a variable xyz, which you now want to rename to something more meaningful. In Visual Studio .Net 2003, what options did you have? You could do a find and replace for “xyz” (to rename it to something else, says “username”), but this would also rename variables like “abcxyz” to “abcusername”! You could of course choose the “Find whole word” option, but another problem – this would also rename variables named “xyz” in other classes which you might not want to touch.

 


The Visual C# 2005 IDE has a new feature which you can use. Lets look at the screen shot below:

In the above image, I want to rename the "username" variable. Within the Visual C# 2005 IDE, I right click on the variable name. Within the context menu that pops up, I choose "Refactor" and then "Rename". A dialog box pops up as shown in the image below:

I type in the new variable name. Suppose I type in "newusername". The IDE determines what all changes have to be made within the solution. Look the image below. You'll see that both instances of "username"  have been changed to "myusername".

What's so great you might ask - after all, this could have been done by a simple find and replace. You're right - but that would have worked only for this simple case. Assume "username" was a public variable, and was being used by other classes too. On renaming the variable using the refactoring method above, all the places where the variable was being used (within the current solution), would get renamed to the new name.

1 2 3 4

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us