samedi 12 juin 2021

How to easily merge two anonymous objects with different data structure?

I would like to merge these two anonymous objects:

var man1 = new {
    name = new {
        first = "viet"
    },
    age = 20
};

var man2 = new {
    name = new {
        last = "vo"
    },
    address = "123 street"
};

Into a single one:

var man = new {
    name = new {
        first = "viet",
        last = "vo"
    },
    age = 20,
    address = "123 street"
};

I looked for a solution but found nothing clever.





Aucun commentaire:

Enregistrer un commentaire