Question

When I am running a C# code in debug mode. I can add objects to watch window and explore them, or I can view them in quick watch.

I am creating an application where I want to show user a window with an object, and he should be able to explore the shown object. Is it possible to have this using some existing API. Or I have an option of using any grammar explorer like Irony to achieve the same.

Just in case you require more information regarding the application, I am creating some objects depending on users inputs and showing user the object created, which he can explore to check if everything is right, he can modify them if required, intended user-base for this application are developers itself.

Was it helpful?

Solution

If you want the user to be able to explore the object data:

You can use the ObjectDumper class that has been known to do that. I've never confirmed, but I've always suspected that the Immediate Window uses that.

From the project site:

ObjectDumper takes a normal .NET object and dumps it to a string, TextWriter, or file. Handy for debugging purposes.

This class library for.NET 3.5 and 4.0 enables you to take an object instance and easily dump its contents to a string, Debug-output, a TextWriter, or to a file. Handy for debugging purposes.

Or do it by yourself:

foreach(PropertyDescriptor descriptor in TypeDescriptor.GetProperties(obj))
{
    string name=descriptor.Name;
    object value=descriptor.GetValue(obj);
    Console.WriteLine("{0}={1}",name,value);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top