How Do I Create an Expression> with Type Parameters from a Type Variable

后端 未结 3 1340
终归单人心
终归单人心 2021-01-02 08:43

I\'d like to write a statement like the following:

Expression> filter = x => true;

Except instead of

3条回答
  •  醉酒成梦
    2021-01-02 09:17

    You'll need to create an expression with a body set to the constant true and a parameter of the type of your type. There is an Expression to do each of these things:

    Type type = typeof(object);
    var lambda = Expression.Lambda(
        Expression.Constant(true), 
        Expression.Parameter(type, "parameter"));
    

提交回复
热议问题