Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.
Just wanted to make a quick post about a long forgotten friend the DebuggerDisplay attribute.The DebuggerDisplayAttribute Class controls how an object, property, or field is displayed in the debugger variable windows. This attribute can be applied to types, delegates, properties, fields, and assemblies. The DebuggerDisplay attribute has a single argument, which is a string to be displayed in the value column for instances of the type. This string can contain braces ({ and }). Text within a pair of braces is evaluated as a field, property or method.
The string can be set to private and still work. Read a recent article https://blogs.msdn.microsoft.com/jaredpar/2011/03/18/debuggerdisplay-attribute-best-practices/ that has a bunch of other suggestions.
Awesome post!
Couple of tips:
1. Little known fact about the DebuggerDisplayAttribute is that you can actually use it on 3rd part types (meaning classes you don’t have the source code for) – see http://stackoverflow.com/a/4475679/292555
2. [Disclaimer: I’m the co-creator of the product I’m mentioning here] A bunch of years ago I got so frustrated with having to recompile my code every time I wanted to change the way an object is created in the debugger, that I created a commercial extension to Visual Studio (http://www.oz-code.com) that lets you do the equivalent of DebuggerDisplay dynamically at debug time – see https://www.youtube.com/watch?v=gg0hGWKOBoo