下面的代码可以工作,但是我想介绍一个ToUpper()
var predicate =
Expression.Lambda<Func<T, bool>>(
Expression.Call(
Expression.PropertyOrField(parameter, "FirstName"),
"Contains", null,
Expression.Constant("myvalue".ToUpper())), parameter
);
结果是:
{Param_0 => Param_0.FirstName.Contains("MYVALUE")}
但是我想要这样:
{Param_0 => Param_0.FirstName.ToUpper().Contains("MYVALUE")}
我该如何改变?
最佳答案
只需添加一个Expression.Call
:
var predicate =
Expression.Lambda<Func<T, bool>>(
Expression.Call(
Expression.Call( // <=== this one is new
Expression.PropertyOrField(parameter, "FirstName"),
"ToUpper", null),
"Contains", null,
Expression.Constant("myvalue".ToUpper())), parameter
);
然后将其报告为:
Param_0 => Param_0.FirstName.ToUpper().Contains("MYVALUE")
关于c# - Expression.Call中的ToUpper(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13986573/