VB.NET:" lambda表达式不能转换为EX pression树"编译时错误 [英] VB.NET : "Statement lambdas cannot be converted to expression trees" compile time error

查看:174
本文介绍了VB.NET:" lambda表达式不能转换为EX pression树"编译时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为什么能做到以下几点:

Why can I do the following :

Dim qNodes As IQueryable(Of XmlNode) = xDoc.ChildNodes.AsQueryable()
Dim test = qNodes.Where(Function(node) True)

虽然下面给出我的标题所述的错误:

although the following gives the error I stated in the title :

Dim qNodes As IQueryable(Of XmlNode) = xDoc.ChildNodes.AsQueryable()
Dim test = qNodes.Where(Function(node)
                               Return True
                           End Function)

我真的不明白这一点。

推荐答案

这是在VB.NET 10语言规范的第11.1节指出:

This is stated in section 11.1 of the VB.NET 10 Language Specification:

拉​​姆达之间的精确翻译   方法和EX pression树可以不   被各版本之间的固定   编译器和超出的范围   本说明书。对于微软   Visual Basic中10.0,所有的lambda   前pressions可转化成   EX pression树木受   以下限制:

The exact translation between lambda methods and expression trees may not be fixed between versions of the compiler and is beyond the scope of this specification. For Microsoft Visual Basic 10.0, all lambda expressions may be converted to expression trees subject to the following restrictions:

      
  1. 只有单行拉姆达EX pressions没有的ByRef参数   可被转化为前pression树木。   单行子lambda表达式,只   调用语句可以被转换   能恩pression树木。
  2.   
  3. 匿名类型EX pressions不能转换为EX pression树如果   早期的字段初始值是用来   初始化后续场   初始化,例如新增功能{.A = 1,   .B = .A}
  4.   
  5. 在对象初始EX pressions不能转换为EX pression   树木如果当前的一个成员   对象正在初始化用于   现场初始化之一,例如   新C1随着{.A = 1,.B = .Method1()}
  6.   
  7. 多维数组创建EX pressions只能转换为   如果EX pression树木,他们申报   元素明确的类型。
  8.   
  9. 在后期绑定EX pressions不能转换为EX pression树木。
  10.   
  11. 当一个变量或字段被传递给ByRef的调用   前pression但不具有完全相同   的相同类型的参数的ByRef,   或者当一个属性通过为ByRef,   正常VB语义是副本   参数传递的ByRef及其   最终的值然后复制回   变量或字段或属性。在   EX pression树木,复制回做   不会发生。
  12.   
  1. Only single-line lambda expressions without ByRef parameters may be converted to expression trees. Of the single-line Sub lambdas, only invocation statements may be converted to expression trees.
  2. Anonymous type expressions cannot be converted to expression trees if an earlier field initializer is used to initialize a subsequent field initializer, e.g. New With {.a=1, .b=.a}
  3. Object initializer expressions cannot be converted to expression trees if a member of the current object being initialized is used in one of the field initializers, e.g. New C1 With {.a=1, .b=.Method1()}
  4. Multi-dimensional array creation expressions can only be converted to expression trees if they declare their element type explicitly.
  5. Late-binding expressions cannot be converted to expression trees.
  6. When a variable or field is passed ByRef to an invocation expression but does not have exactly the same type as the ByRef parameter, or when a property is passed ByRef, normal VB semantics are that a copy of the argument is passed ByRef and its final value is then copied back into the variable or field or property. In expression trees, the copy-back does not happen.

所有这些限制适用于嵌套   拉姆达EX pressions为好。

All these restrictions apply to nested lambda expressions as well.

有限制的,你正在运行到的第一个项目。引进留下充足的空间来承担,这将在以后的版本中工作着,还有很多可以得到的,当然。 Connect.microsoft.com是一个很好的地方去鼓励他们。我不能检查,如果反馈项目已经开了这一点,该网站是在弗里茨现在。

It is the restriction in the first item that you are running into. The introduction leaves plenty room to assume that this will be worked on in future releases, there's much to be gained of course. Connect.microsoft.com is a good place to go to encourage them. I couldn't check if a feedback item was already opened for this, the site is on the fritz right now.

这篇关于VB.NET:" lambda表达式不能转换为EX pression树"编译时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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