开发者

.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 an开发者_如何转开发ything 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.


You can write your code like this: From item in Products Where (item as dynamic).color="red" select item

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜