Visual Studio 2017 Code Refactoring – Sync up Class and File names

Sometimes your C# file name and class name are different for whatever reason and you want to fix it. The usual way of “fixing” this issue is either by renaming the file name in solution explorer or changing the class name using Ctrl R + Ctrl R shortcut. None of these are two that bad of options but Visual Studio 2017 has introduced a better way of handle this scenario. Let’s consider following scenario where class name is Foos whereas the file name is Foo.cs.


Let’s say the class Foos is used as follows.


Within Visual Studio 2017, if you click the cursor on the class name and then press the Quick re-factoring shortcut (Ctrl + .), you will get the two options of either renaming the file or renaming the class as shown in figure below.



Let’s say I choose to rename the type of Foos to Foo from the menu item. With one click, it will not only rename the class itself but also wherever this class is referred as shown below.




Until next, happy debugging!!

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s