【发布时间】:2015-04-18 18:42:04
【问题描述】:
我有一个带有 select 的 Linq 查询,从我的 Linq 查询提供程序我得到一个包含 MethodCallExpression 的 表达式树,但我怎样才能获得选择 projections 来自MethodCallExpression?
internal static object Execute(Expression expression, bool isEnumerable)
{
var whereExpression = expression as MethodCallExpression;
if (whereExpression == null) throw new InvalidProgramException("Error");
foreach (var arg in whereExpression.Arguments)
{
if (arg is UnaryExpression)
{
var unaryExpression = arg as UnaryExpression;
var lambdaExpression = unaryExpression.Operand as LambdaExpression;
if (lambdaExpression == null) continue;
// Here I would like to get the select projections, in this example the "word" projection ...
查询可能如下所示:
var queryable = new MyQueriableClass();
var query = from thing in queryable
where thing.id == 1
select word;
【问题讨论】:
标签: c# .net linq expression-trees