While debugging an ASP.NET application, I want to get a print-out of the entire state of a very large object. I want all the properties and values in that object and the same for every object-property, recursively.
Because the front-end of the application times out after a significant delay, I can’t add a watch or use the Immediate window or hover over the object, since there won’t be adequite time to fully examine the object.
Is there a way of getting a complete printout of an object in debug mode, or say, a utility or a C# function that would do this?
You could use reflection to get the list of all properties and fields on the class type, then use that to get the runtime values of each of those properties / values and spit them to the console.
The
PropertyInfotype (here) andFieldInfotype (here) are what you need to get from theTypeobject for your own class instance.