How to create Expression>;

前端 未结 1 1266
暗喜
暗喜 2021-01-05 19:04

Is it possible to create Expression>() which can be used in different htmlHelpers (for instance in CheckBoxFor()), i

1条回答
  •  不知归路
    2021-01-05 19:31

    Sure:

    static Expression> CreateExpression(
        string propertyName)
    {
        var param = Expression.Parameter(typeof(TModel), "x");
        return Expression.Lambda>(
            Expression.PropertyOrField(param, propertyName), param);
    }
    

    then:

    var lambda = CreateExpression("IsAlive");
    

    0 讨论(0)
提交回复
热议问题