【问题标题】:Building a lambda with an Expression Tree使用表达式树构建 lambda
【发布时间】:2012-07-20 18:18:22
【问题描述】:

我很难掌握表达式树。我希望能够为以下语句手动构建表达式树:

c => c.Property

很多教程都集中在比较上,而我只希望它返回这个属性。有什么帮助吗?

【问题讨论】:

    标签: linq c#-4.0 expression-trees


    【解决方案1】:
    ParameterExpression parameter = Expression.Parameter(typeof(YourClass), "c");
    Expression property = Expression.PropertyOrField(parameter, "Property");
    Expression<Func<YourClass, PropertyType>> lamda = Expression.Lambda<Func<YourClass, PropertyType>>(property, parameter);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      相关资源
      最近更新 更多