I need to copy all properties of an object into anonymous object. In JavaScript I'd do it the following way:
items.map(item => ({...item, extra = 'additional property'}))
In C# I would have to copy property by property:
items.Select(item => new { item.Prop1, item.Prop2, Extra = "additional property" })
Or alternatively I'd use reflection and ExpandoObject
. Any other thoughts?
Aucun commentaire:
Enregistrer un commentaire