protected Expression EvaluateSubtree(Expression subtree) { ArgumentUtility.CheckNotNull("subtree", subtree); // Start custom digression from Relinq sealed base var binary = subtree as BinaryExpression; var checker = new DynamicMemberMetadataFindingVisitor(); checker.VisitExpression(subtree); if (checker.ContainsDynamic) { return(subtree); } //if (binary != null) //{ // var method = binary.Left as MethodCallExpression; // if (method != null) // { // if (method.Method == DynamicMemberMetadata.GetMemberMethod) // { // return subtree; // } // } // var unary = binary.Left as UnaryExpression; // if (unary != null) // { // var innerMethod = unary.Operand as MethodCallExpression; // if (innerMethod != null) // { // if (innerMethod.Method == DynamicMemberMetadata.GetMemberMethod) // { // return subtree; // } // } // } //} // End digression if (subtree.NodeType != ExpressionType.Constant) { return (Expression.Constant( Expression.Lambda <Func <object> >( Expression.Convert(subtree, typeof(object)), new ParameterExpression[0]).Compile()(), subtree.Type)); } var constantExpression = (ConstantExpression)subtree; var queryable = constantExpression.Value as IQueryable; if (queryable != null && queryable.Expression != constantExpression) { return(queryable.Expression); } else { return(constantExpression); } }
protected Expression EvaluateSubtree(Expression subtree) { ArgumentUtility.CheckNotNull("subtree", subtree); // Start custom digression from Relinq sealed base var binary = subtree as BinaryExpression; var checker = new DynamicMemberMetadataFindingVisitor(); checker.VisitExpression(subtree); if (checker.ContainsDynamic) return subtree; //if (binary != null) //{ // var method = binary.Left as MethodCallExpression; // if (method != null) // { // if (method.Method == DynamicMemberMetadata.GetMemberMethod) // { // return subtree; // } // } // var unary = binary.Left as UnaryExpression; // if (unary != null) // { // var innerMethod = unary.Operand as MethodCallExpression; // if (innerMethod != null) // { // if (innerMethod.Method == DynamicMemberMetadata.GetMemberMethod) // { // return subtree; // } // } // } //} // End digression if (subtree.NodeType != ExpressionType.Constant) return Expression.Constant( Expression.Lambda<Func<object>>( Expression.Convert(subtree, typeof (object)), new ParameterExpression[0]).Compile()(), subtree.Type); var constantExpression = (ConstantExpression) subtree; var queryable = constantExpression.Value as IQueryable; if (queryable != null && queryable.Expression != constantExpression) return queryable.Expression; else return constantExpression; }