Diamond In The Rough

I’m still working on my next ASP.NET MVC article. However, I thought that I would share something in the meantime. I’ve been browsing through Microsoft Visual Studio 2015 Unleashed (3rd Edition) a little bit each day. I borrowed this title from the library, and I was hoping that I would stumble on some little tidbits that I was not yet familiar with.

I’ve been using Visual Studio since the 2008 version, but I’m certain that there are many features I have not tapped into yet. I’ve never taken a dedicated course or read a dedicated book focused solely on Visual Studio, so I can guarantee that there are many gems waiting to be discovered.

The feature that I read about this week that I am most excited about is the Extract Method feature. When working on a legacy code base, have you ever stumbled across a method that does way to many things? I know that I have, and I have to admit that I’ve been guilty of writing some of those methods. Fortunately, Visual Studio makes it easy to break apart methods like that into separate methods that each have single purpose.

In order to leverage the feature, you simply need to highlight a block of code that you would like to move to a separate method. Once you’ve done this, you right-click on the code and select Quick Actions and Refactorings. Next, click on Extract Method. Visual Studio will prompt you to rename the method to something appropriate. Below is a screenshot demonstrating this feature being used for a contrived example.

I’m sure that I’ll find plenty of opportunities to use the Extract Method feature in the coming weeks. In the meantime, I’ll be looking forward to picking up on more hidden gems within Visual Studio. If you have a favorite Visual Studio feature that is not so obvious, feel free to leave a comment below and share your finding.