Breakpoints in Auto-Properties in Visual Studio 2015

By December 30, 2016Visual Studio

This tip falls squarely into the category of simple, yet oh so useful. Visual Studio 2015 isn’t exactly new, but I am still discovering things that make it nice for debugging. That’s where I’ve spent a lot of my time this week, and one thing that has saved me is using Actions on breakpoints to print messages to the console. And surprise! You can do the same thing even when using auto-properties in Visual Studio 2015 without backing fields.

First, if you haven’t checked out Actions on breakpoints, go ahead and catch up from one of Falafel’s Visual Studio 2015 posts.

Automatic Properties

An automatic property may look like you can’t set a breakpoint, but you can. In this example we will put one on the setter. Position your cursor after the setter and use the context menu to add a breakpoint.

2016-12-30-15_09_22-c__users_rachel_documents_visual-studio-2015_projects_decblogconsoleapp-decblogc  2016-12-30-15_10_00-c__users_rachel_documents_visual-studio-2015_projects_decblogconsoleapp-decblogc

Printing the Value

Now, how can we print the value getting set to the console? If this were a property with a backing field, we would use the value inside the setter, right?

2016-12-30-15_07_55-c__users_rachel_documents_visual-studio-2015_projects_decblogconsoleapp-decblogc

Well, we can still use the value keyword inside of our Action console statement. Yes, it will work! Intellisense agrees with me.

2016-12-30-15_11_36-c__users_rachel_documents_visual-studio-2015_projects_decblogconsoleapp-decblogc

And voila  – we can see the values being set in the console!

2016-12-30-15_13_02-c__users_rachel_documents_visual-studio-2015_projects_decblogconsoleapp-decblogc

Did you learn something? Check out more of Falafel’s blogs covering Visual Studio 2015.

The following two tabs change content below.

Latest posts by Guest Posts (see all)