【发布时间】:2016-09-20 18:20:59
【问题描述】:
在将我的 .NET 4.5 库转换为 .NETStandard v1.6 时,我遇到了以前通过的单元测试失败。
我将问题定位在以下三行代码:
ParameterExpression arg1 = Expression.Parameter( typeof( DateTime ), "arg1" );
ParameterExpression arg2 = Expression.Parameter( typeof( DateTime ), "arg2" );
var test = Expression.Subtract( arg1, arg2 );
此表达式树编译为.NET 4.5,但在.NETStandard v1.6 中抛出InvalidOperationException:
没有为类型定义二元运算符 Subtract 'System.DateTime' 和 'System.DateTime'。
但是,对于这两个目标,以下代码都有效:
DateTime one = new DateTime();
DateTime two = new DateTime();
TimeSpan difference = one - two;
因此我希望表达式树也可以为 .NET Core 编译?我做错了什么,还是is this a bug in .NET Core?
【问题讨论】:
-
我刚刚尝试过使用常量表达式 (
Expression.Constant( DateTime.Now )),同样的情况。 -
来自a quick glance at the source code,
GetUserDefinedBinaryOperator似乎正在返回null。
标签: c# expression-trees .net-core .net-core-rc2