Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net expando object and LINQ. Possible or not?

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.

like image 666
alainb Avatar asked Mar 26 '11 22:03

alainb


1 Answers

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.

like image 127
Ghassen Hamrouni Avatar answered Sep 20 '22 16:09

Ghassen Hamrouni