How do I create a generic Expression that has an expression as a parameter

前端 未结 4 1937
死守一世寂寞
死守一世寂寞 2021-01-06 18:32

There is a DisplayNameFor(x=>x.Title) helper in ASP.Net MVC. I want to implement something similar in behavior.

I want to have a method that accepts

4条回答
  •  一个人的身影
    2021-01-06 19:14

    The below method will produce a binary expression that will have a boolean return value

    Expression> 
         GenerateAssignExpression(
             Expression> expression,
             ExpressionType op, 
             TProperty Value)
        {   
            return Expression.Lambda>(
                Expression.MakeBinary(op, expression, Expression.Constant(Value)),
                getExpression.Parameters[0]);
        }
    

    if you wish for a generic return type just change the Predicate to Func (You need to replace both occurrences of `Predicate´

提交回复
热议问题