Visual Studio 2017 Code Refactoring – Moving a class into its own file

Visual Studio 2017 has introduced new quick ways to refactor your code. One such refactoring is about moving a class in a new file. There are use cases when a developer may have created many classes in a single file. As shown in figure below, Let’s say I have two classes Foo and Bar in the same file called Foo.cs.

Capture

With Visual Studio 2017 refactoring improvements, its now much easier to move classes into a separate file of its own. In order to do that you just move cursor on the class name Bar within the Editor and right click. This will show the familiar menu options including “Quick Actions and Refactorings”.

Untitled

You can either choose this menu option or the shortcut Ctrl + . which will bring up the new refactoring option of “Move type into Bar.cs”.

Untitled2.png

Once you choose that option, the class Bar will be moved to a new file called Bar.cs as shown in image below.

Capture2

Until next, happy debugging!!!

 

Advertisements
This entry was posted in Visual Studio 2017. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s