A known issue with using VisualStudio is the cryptic calling of property recipients. If they have side effects (the most common of the forms if (foo == null) foo = new foo(); return foo;), then the fact that the Locals and Watch debug windows invoke properties β even without hitting any breakpoints β can lead to unexpected debugging consequences.
There is a simple solution: just mark the property with an attribute
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
So, how can I find getters that can have side effects in a large code base?
NDepend is the tool of choice for this kind of thing: using my CQL language, I can find all the properties that, for example, directly change the state of my containing instance:
SELECT METHODS FROM ASSEMBLIES "FOO"
WHERE IsPropertyGetter AND ChangesObjectState
It only finds those getters that directly change the field: how can I find those that indirectly change it, for example. by calling a method Initialize()?
source
share