ToString method when using .Dump

Hi,

Would it be possible to get a feature implemented in linqpad, where linqpad does not call .ToString() on the objects being dumped.

The reason for this that if you have implemented a ToString() method on a class you don't neccessary want it to be used when calling .Dump().

Example:
----------------------------------------------------
void Main()
{

var c = new ClassWithToString();

c.Dump();

var c2 = new ClassWithoutToString();
c2.Dump();

}

public class ClassWithoutToString
{
public int MyProperty { get; set; }
public int MyProperty2 { get; set; }
public int MyProperty3 { get; set; }

}

public class ClassWithToString : ClassWithoutToString
{
public override string ToString()
{
return $@{MyProperty},
{MyProperty},
{MyProperty}";
}

}
----------------------------------------------------

In this example the result for ClassWithToString in the dump window looks silly, since Dump calls ToString() as part of dumping.

Where for the ClassWithoutToString looks as "expected" - where it just uses the name of the class.

Thanks in advance

Comments

  • You could customize Dump with ToDump in MyExtensions to avoid ToString:
    static object ToDump(object obj) {
            if (obj.GetType().GetMethod("ToString") != null)
                  return Util.ToExpando(obj);
            else
                  return obj;
    }
    Though you may want to restrict it to your own types.

    Also, you could add ToDump to your own classes:

    https://linqpad.net/CustomizingDump.aspx
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!