【发布时间】:2018-04-24 23:13:52
【问题描述】:
从昨天开始,我一直在自学表达式树,但在比较两个字符串值时遇到了问题。我制作了这个失败的测试用例:
No method 'Compare' on type 'System.String' is compatible with the supplied arguments.
left = Expression.Call( 运行时失败
Type type = typeof(string);
Expression left, right;
left = Expression.Constant("1", type);
right = Expression.Constant("2", type);
// fails at run-time on the next statement
left = Expression.Call(
typeof(string),
"Compare",
new Type[] { type, type },
new Expression[] { left, right });
right = Expression.Constant(0, typeof(int));
我将在Expression.Equal, LessThan, LessThanOrEqual, GreaterThan or GreaterThanOrEqual 中使用得到的左右。这就是使用 Compare 方法的原因。
我确信它很简单,我已经将我的代码归结为这个简单的测试用例。有人看到我哪里出错了吗?
【问题讨论】:
标签: c# expression expression-trees