RepoWrapper icon indicating copy to clipboard operation
RepoWrapper copied to clipboard

Not able to retrieve value from BinaryExpression.Right

Open jabreuar opened this issue 7 years ago • 0 comments

I was trying to use the WalkTree method, but it was getting an error: propertyValue.Value is not defined.

I already fixed it. I just built a new method to retrive the value from a BinaryExpression:

private static void WalkTree(BinaryExpression body, ExpressionType linkingType, ref List<QueryParameter> queryProperties) { if (body.NodeType != ExpressionType.AndAlso && body.NodeType != ExpressionType.OrElse) { string propertyName = GetPropertyName(body); dynamic propertyValue = GetValue(body); string opr = GetOperator(body.NodeType); string link = GetOperator(linkingType);

            queryProperties.Add(new QueryParameter(link, propertyName, propertyValue, opr));
        }
        else
        {
            WalkTree((BinaryExpression)body.Left, body.NodeType, ref queryProperties);
            WalkTree((BinaryExpression)body.Right, body.NodeType, ref queryProperties);
        }
    }

    private static object GetValue(BinaryExpression func)
    {
        return Expression.Lambda(func.Right).Compile().DynamicInvoke();
    }

Btw, very nice implementation 👍

jabreuar avatar Jul 04 '17 18:07 jabreuar