How to use LINQ with dynamic collections

后端 未结 3 2013
小鲜肉
小鲜肉 2020-12-04 11:10

Is there a way to convert dynamic object to IEnumerable Type to filter collection with property.

dynamic data = JsonConvert.Deseri         


        
3条回答
  •  误落风尘
    2020-12-04 11:58

    So long as data is an IEnumerable of some kind, you can use:

    var a = ((IEnumerable) data).Cast()
                                .Where(p => p.verified);
    

    The Cast() is to end up with an IEnumerable so that the type of the parameter to the lambda expression is also dynamic.

提交回复
热议问题