如何使用LINQ与动态集合 [英] How to use LINQ with dynamic collections
本文介绍了如何使用LINQ与动态集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种办法动态
对象转换为的IEnumerable
键入与属性过滤收集。
Is there a way to convert dynamic
object to IEnumerable
Type to filter collection with property.
dynamic data = JsonConvert.DeserializeObject(response.Content);
我需要访问这样的事情
I need to access something like this
var a = data.Where(p => p.verified == true)
任何想法?
推荐答案
只要数据
是某种类型的的IEnumerable
,你可以使用:
So long as data
is an IEnumerable
of some kind, you can use:
var a = ((IEnumerable) data).Cast<dynamic>()
.Where(p => p.verified);
的
演员LT;动态>()
是结束了一个的IEnumerable<动态>
这样的参数lambda表达式的类型也是动态
。
The Cast<dynamic>()
is to end up with an IEnumerable<dynamic>
so that the type of the parameter to the lambda expression is also dynamic
.
这篇关于如何使用LINQ与动态集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文