Alecu
Alecu

Reputation: 2708

C# check to see if property is accessed by the visual studio debugger

I am writing a C# application. I have some objects with some lazy properties that actually do quite some work when you request their values.

I want to be able to check if they are called by the visual studio debugger when debugging and not execute them at all. For example when I click on an object with these properties then it shouldn't load them at all.

How can I do this?

Upvotes: 1

Views: 821

Answers (2)

Thomas Weller
Thomas Weller

Reputation: 59238

Besides the excellent suggestion of @mjwills, if you don't have the source code or don't want to modify it at this point in time, turn the feature of in VS:

VS Option dialog

Upvotes: 2

mjwills
mjwills

Reputation: 23819

Consider using DebuggerBrowsableAttribute:

[DebuggerBrowsable(DebuggerBrowsableState.Never)]

The docs state:

Never -> Never show the element.

https://lostechies.com/jamesgregory/2009/08/18/debugger-property-evaluation-side-effects/ also briefly discusses the attribute.

Upvotes: 3

Related Questions