C# - display information about custom objects in VS during debugging
I have a set of C# classes, extending an abstract class. There is an abstract method void Show()
on the parent. The extending classes are part of a graph with cycles. The implementations of Show invoke many times Console.Write()
. Between the console writes there are recursive and other 开发者_StackOverflow社区calls.
My problem - it is very hard to debug without an easy way to see the state of the graph. I've tried to make that method string Show()
, but it is very hard to do properly with all the recursion and cycles. Can you suggest a better approach?
Thanks, Sam
Consider using DebuggerDisplay rather than ToString. See these excellent articles:
- Why override ToString()? Use DebuggerDisplayAttribute instead
- DebuggerDisplay attribute best practices
override your ToString() method, the tooltip window shown by the debugger uses this method to show any relevant data related to your object.
精彩评论