MoaidHathot / Dumpify

Adding `.Dump()` extension methods to Console Applications, similar to LinqPad's.
MIT License
991 stars 42 forks source link

Use columns for properties when dumping collections? #30

Open wilka opened 4 months ago

wilka commented 4 months ago

One of the handy things with LinqPad .Dump() is when you use it on a collection, you get a table with columns for each property. e.g. in LinqPad the code:

void Main()
{
    var people = new[] 
    {
        new Person("Marie", "Curie"),   
        new Person("Albert", "Einstein"),
        new Person("Ada", "Lovelace"),
        new Person("Cleopatra", "Philopator"),
        new Person("Nikola", "Tesla")
    };

    people.Dump();
}

record Person(string FirstName, string LastName);

gives: image

but with Dumpify, it shows: image

So I'd like to be able to have the more concise column-for-property format with collections.

MoaidHathot commented 4 months ago

Hi @wilka, a similar feature is already supported but it is turned-off by default. It can be turned-on either globally for all dumps or per-dump:

Globally: DumpConfig.Default.TableConfig.ShowRowSeparators = true;

Per dump: people.Dump(tableConfig: new TableConfig { ShowRowSeparators = true });

Turning this option on results in the following output: image

MoaidHathot commented 4 months ago

I know this isn't exactly like what you get from LinqPad, but I'm wondering how we can generalize this. LinqPad basically transposes the table. I will think about it and how it can fit in Dumpify while taking terminal width limitations into account. Thanks for the suggestion!

wilka commented 4 months ago

If it makes any difference, I'm not hugely concerned about the terminal width limits. I tend to run my Windows Terminal at full screen, and I have a large display. But I realise that won't be the case for everyone.

I've been using Dumpify as a stepping stone from taking some LinqPad prototype code, and then turning it into a console app.