本文介绍了ToUpper的()在防爆pression.Call的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面工作的code,但我想介绍一个 ToUpper的()

The code below work, but I'd like introduce a 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")}

不过,我想这样的:

But I'd like this :

{Param_0 => Param_0.FirstName.ToUpper().Contains("MYVALUE")}

我如何更改?

How can I change ?

推荐答案

只需添加一个防爆pression.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
        );

然后自己报告如下:

which then reports itself as:

Param_0 => Param_0.FirstName.ToUpper().Contains("MYVALUE")

这篇关于ToUpper的()在防爆pression.Call的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:13