khalidabuhakmeh / ConsoleTables

Print out a nicely formatted table in a console application C#
MIT License
944 stars 157 forks source link

Support value tuples in addition to objects #72

Closed scharnyw closed 4 months ago

scharnyw commented 4 months ago

Run the following snippet:

var objects = new[]
{
    new
    {
        Column1 = "value1",
        Column2 = "value2"
    },
    new
    {
        Column1 = "value3",
        Column2 = "value4"
    }
};

ConsoleTable
    .From(objects)
    .Write();

var tuples = new[]
{
    (
        Column1: "value1",
        Column2: "value2"
    ),
    (
        Column1: "value3",
        Column2: "value4"
    )
};

ConsoleTable
    .From(tuples)
    .Write();

Writing anonymous type objects succeed with no problem but doing it with (un)named value tuples fails with System.Exception: 'Please set the columns first'.

Considering that value tuples are popular these days for doing a quick projection, etc. it would be nice if they can be supported. I can submit a PR if contributions are welcome.