在尝试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.
更多推荐
发布评论