How to cast Expression> to Expression>

后端 未结 4 1833
借酒劲吻你
借酒劲吻你 2020-11-29 02:12

I\'ve been searching but I can\'t find how to cast from the type

Expression>

to the type:

Exp         


        
4条回答
  •  孤独总比滥情好
    2020-11-29 02:38

    Based on the code from Jon (thanks btw) you can take it one step further for complete flexibility:

    public static Expression> Cast(Expression> expression)
    {
        Expression converted = Expression.Convert(expression.Body, typeof(TToProperty));
    
        return Expression.Lambda>(converted, expression.Parameters);
    }
    

提交回复
热议问题