I have a simple list of expando objects called products.
i add various fields to these objects at runtime ( for example color or size)
How can i write a LINQ query on this list based on dynamic fields ?
With a classic list of objects i could write a LINQ query like this :
From item in Products Where item.color="red" select item
but with expandos , how this can be achieved , knowing that i don't know in advance the name of the fields (it could be size of weight or anything else ) ?
Thank you in advance.
The expando object implements IDictionary(Of String, Object) Thus you could cast it to an IDictionary and access it's properties by passing a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With