0

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 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

2 Answers 2

2

Consider using DebuggerDisplay rather than ToString. See these excellent articles:

Sign up to request clarification or add additional context in comments.

Comments

1

override your ToString() method, the tooltip window shown by the debugger uses this method to show any relevant data related to your object.

4 Comments

Those Show methods are 30-50 lines, with some funky indentation going on. I don't want to rewrite them.
you dont need to rewrite them, just make them return the shown text on the console and then return it by the ToString() method
"I've tried to make that method string Show(), but it is very hard to do properly with all the recursion and cycles."
this trick may help, make a private string buffer, when the show method is called, clear it, when a new line is shown on the console append it to the buffer, in the ToString() method, return that buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.