Given the following example class:
public class MyClass
{
public string S { get; set; }
public int I { get; set; }
public DateTime D { get; set; }
private float F { get; set; }
private long l;
public MyClass()
{
S = "foo";
I = 42;
D = new DateTime(2011, 11, 11);
F = 3.14f;
l = 12435;
}
}
If I in my application have an instance myClass
of this class, step through the code in debug mode (Visual Studio 2010), and at some point types myClass into the Immediate Window, the following is displayed:
{MyClass}
D: {11.11.2011 00:00:00}
F: 3.14
I: 42
l: 12435
S: "foo"
Getting such a string representation of the object and all its values could be very useful for logging purposes. Is there a nice and easy way to achieve this?
I guess the Immediate Window uses reflection to loop over all fields and properties, but I thought I'd ask just in case there already exists some utility function or anything to do it.