Visual Studio Tips & Tricks - Quick Actions

In the previous versions of Visual Studio we have refactoring options such Encapsulate Field, Extract Method etc in the context menu and the Resolve option for adding namespaces when you refer a method which are not imported etc. In VS 2015, these all are clubbed together and will appear in once place called Quick Actions. They also added new features like previewing and integreated search into it making it more productive. Also in statements wherever the quick actions are available, a Light Bulb will be shown in the left side very much like the feature in tools like Reshaper.

To see this in action, let's call a new method which is not defined in the code. The light bulb will immediately appear along with the red squiggly once you complete the statement as shown below.

You can click on the bulb to bring up the suggested action, which is to generate the method stub for PerformAction. If we click on the arrow button, you will get a preview of the content of the method that is going to be generated. This feature is newly added in Visual Studio 2015, earlier we had only the option to generated the method

Also, we have the option to specify the locations where the fix can be applied. The available options are Document, Project and Solution as shown below.

Another feature is that it will also show the error text along with the error code in the extended window.

Another feature introduced in VS 2015 is Inline Temporary Variable. In the snippet given below, we create a new string collection from the array and assigning it to a variable. Then we are filtering out data using the Find method and the result is assigned to another variable. Actually we can do this using a single statement and the code can be refactored using the Inline Temporary Variable feature. 

As soon you complete typing, the light bulb will appear and click on it will give you the option to refactor the code and the result will be as follows.

In the earlier version, when we removed unused Usings from the code, we won't get to know which all items are going to be removed. In VS 2015, using the preview box you easily identify that, all the items that are going to removed will be higlighted as shown below.

Also all the unused ones will be have a dimmed effect to easily identify those in the using block.


No Comments

Add a Comment