简体   繁体   中英

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?

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.

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选项对话框

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM