lambda表达式中的枚举不同;(Enums in lambda expressions are compiled differently; consequence of overload resol

编程入门 行业动态 更新时间:2024-10-05 21:21:32
lambda表达式中的枚举不同;(Enums in lambda expressions are compiled differently; consequence of overload resolution improvements?)

在尝试Visual Studio 2015 RC时,我收到以前工作代码的运行时错误。 给定作为Expression<>传递给函数的lambda (x => x.CustomerStatusID == CustomerStatuses.Active) ,调试器在表达式树中显示不同。 以前它编译为:

.Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 }

但在C#6.0中,它现在编译为

.Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == (System.Int32).Constant<Services.DataClasses.CustomerStatuses>(Active) }

虽然我的树遍历代码的修复是直截了当的,额外的细节是赞赏,有没有人知道任何其他的陷阱像这样漂浮?

或者,有没有人有链接到有关如何改进重载分辨率的具体情况的信息? 我找不到任何东西

While trying out the Visual Studio 2015 RC, I received a run-time error on previously working code. Given the lambda (x => x.CustomerStatusID == CustomerStatuses.Active) which was passed to a function as an Expression<>, the debugger shows a difference in the expression tree. Formerly it compiled as this:

.Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 }

But in C# 6.0 it now compiles as

.Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == (System.Int32).Constant<Services.DataClasses.CustomerStatuses>(Active) }

Although the fix to my tree-traversing code was straightforward and the additional detail is appreciated, does anyone know of any other gotchas floating around like this?

Alternately, does anyone have a link to information on the specifics of how overload resolution was improved? I cannot find any.

最满意答案

这与重载分辨率无关。 以前的编译器过早优化了比较的右侧,从而省略了与源表达式对应的代码。

This has nothing to do with overload resolution. The previous compiler prematurely optimized the right-hand-side of the comparison, thereby omitting the code corresponding to the source expression.

更多推荐

本文发布于:2023-08-07 16:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465229.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   expressions   compiled   lambda   Enums

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!