lambda表达式中的枚举的编译方式不同;重载解析改进的结果

本文关键字:重载 结果 表达式 枚举 编译 方式不 lambda | 更新日期: 2023-09-27 17:51:18

在尝试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)
}

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

或者,谁有关于如何改进重载解析的具体信息的链接?

lambda表达式中的枚举的编译方式不同;重载解析改进的结果

这与重载解析无关。上一个编译器过早地优化了比较的右侧,从而省略了与源表达式对应的代码。