Visual Studio 2017 – Add Braces

Visual Studio 2017 code refactoring improvements also made it easy to adapt to some best practices. One of those is adding braces around your code blocks. Let’s say you have code as follows. There are quite a few if -else conditions handled here but not wrapping this type of code in braces can generate lot of interesting discussion.


My goal is not to re-ignite that type of discussion here again because there is enough already available on internet. What I would like to point out here the new refactoring improvements that can make adding those best practices a little easier. If you look closely, you will notice those gray dots showing up under the if clauses as displayed in red rectangles in image below.


Those gray dots basically provide a hint that you can apply some code refactoring here using old friend Ctrl+. . Doing it will bring up following dialog for adding the braces. As you can see in blue rectangle in image below, you get the option to apply this in your Document, Project or entire Solution.


Let’s say I choose Document here. Doing this will bring up following dialog with preview and a chance to fine-tune where you exactly want to apply this.


At this point, if you hit Apply button, the changes will appear in your code as shown below.


Until next, happy debugging.


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: 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