【发布时间】:2012-07-20 18:18:22
【问题描述】:
我很难掌握表达式树。我希望能够为以下语句手动构建表达式树:
c => c.Property
很多教程都集中在比较上,而我只希望它返回这个属性。有什么帮助吗?
【问题讨论】:
标签: linq c#-4.0 expression-trees
我很难掌握表达式树。我希望能够为以下语句手动构建表达式树:
c => c.Property
很多教程都集中在比较上,而我只希望它返回这个属性。有什么帮助吗?
【问题讨论】:
标签: linq c#-4.0 expression-trees
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);
【讨论】: