IEnumreable动态和lambda [英] IEnumreable dynamic and lambda

查看:322
本文介绍了IEnumreable动态和lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个的IEnumerable℃的lambda表达式;动态> 键入,howerver其中,采用了全新的Lambda表达式IM即时得到的属性,下面的错误,并协调:

I would like to use a lambda expression on a IEnumerable<dynamic> type, howerver im getting the following error on attributes and coordinates where im using a new lambda expression:

无法使用lambda表达式作为参数传递给动态调度的操作,而不首先将其强制转换为委托或表达式树类型

下面是我的代码

public static object returnFullSelectWithCoordinates(IEnumerable<dynamic> q)
        {
            return q.Select(b => new
            {
                route_id = b.b.route_id,
                name = b.b.name,
                description = b.b.description,
                attributes = b.b.route_attributes.Select(c => c.route_attribute_types.attribute_name),
                coordinates = b.b.coordinates.Select(c => new coordinateToSend { sequence = c.sequence, lat = c.position.Latitude, lon = c.position.Longitude })

            });

有任何解决方法,使我的方法的工作?

Is there any workaround to make my method work?

推荐答案

由于选择<> 是一个扩展方法,它不会在动态类型的工作。

Since Select<> is an extension method, it won't work on dynamic types.

您可以通过使用相同的结果 Enumerable.Select<>

You can get the same result by using Enumerable.Select<>.

试试这个查询:

Enumerable.Select(q,(Func<dynamic,dynamic>)(b => new
        {
            route_id = b.b.route_id,
            name = b.b.name,
            description = b.b.description,
            attributes = b.b.route_attributes.Select(c => c.route_attribute_types.attribute_name),
            coordinates = b.b.coordinates.Select(c => new coordinateToSend { sequence = c.sequence, lat = c.position.Latitude, lon = c.position.Longitude })

        });

这篇关于IEnumreable动态和lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆