Visual Studio 2017 – Simplified Object Initialization

Visual Studio 2017 introduced code refactoring to simplify object initialization. Let’s say we have following class called Bar.

1

And here is how this class is consumed.

2

Notice the Gray dots under the new keyword in this picture. This is an indication that there is some code refactoring available. In order to view it, just click the Ctrl+. and it will bring up following pop-up.

3

As you can see in this image, the suggested change is to initialize the BarId and BarName properties using Object Initializer. If you choose to apply this suggestion, the updated code will look as follows.

4

Until next, happy debugging.

 

Advertisements
This entry was posted in Uncategorized. 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