C# How to convert an Expression> to an Expression>

后端 未结 4 1690
轮回少年
轮回少年 2020-12-14 10:46

I have used C# expressions before based on lamdas, but I have no experience composing them by hand. Given an Expression> originalPredi

4条回答
  •  旧巷少年郎
    2020-12-14 11:31

    There is no implicit way to do the translation. You have to wrap your existing delegate inside a lambda that creates a new type from the argument type:

    var translatedPredicate = x => originalPredicate(OtherTypeFromSomeType(x))
    

    Where OtherTypeFromSomeType creates the OtherType instance from the SomeType argument.

提交回复
热议问题