Exemple #1
0
        /// <summary>
        /// Trys to take 2 expressions returned from FindIEnumerable and join them together. I.e. If we Split list.First() with FindIEnumerable, we can join it back together with newList.First()
        /// </summary>
        /// <param name="baseExp"></param>
        /// <param name="nextExp"></param>
        /// <returns></returns>
        public static Expression CombineExpressions(Expression baseExp, Expression nextExp)
        {
            switch (nextExp.NodeType)
            {
            case ExpressionType.Call:
            {
                var mc = (MethodCallExpression)nextExp;
                if (mc.Object == null)
                {
                    var args = new List <Expression> {
                        baseExp
                    };
                    var newParam = Expression.Parameter(baseExp.Type.GetGenericArguments().First());
                    foreach (var item in mc.Arguments.Skip(1))
                    {
                        var lambda = (LambdaExpression)item;
                        var exp    = new ParameterReplacer().Replace(lambda, lambda.Parameters.First(), newParam);
                        args.Add(exp);
                    }
                    var call = ExpressionUtil.MakeExpressionCall(new[] { typeof(Queryable), typeof(Enumerable) }, mc.Method.Name, baseExp.Type.GetGenericArguments().ToArray(), args.ToArray());
                    return(call);
                }
                return(Expression.Call(baseExp, mc.Method, mc.Arguments));
            }

            default: throw new EntityGraphQLCompilerException($"Could not join expressions '{baseExp.NodeType} and '{nextExp.NodeType}'");
            }
        }
Exemple #2
0
        public static Expression SelectDynamic(ParameterExpression currentContextParam, Expression baseExp, IEnumerable <IGraphQLNode> fieldExpressions, ISchemaProvider schemaProvider)
        {
            Type dynamicType;
            var  memberInit = CreateNewExpression(currentContextParam, fieldExpressions, schemaProvider, out dynamicType);
            var  selector   = Expression.Lambda(memberInit, currentContextParam);

            return(ExpressionUtil.MakeExpressionCall(new [] { typeof(Queryable), typeof(Enumerable) }, "Select", new Type[2] {
                currentContextParam.Type, dynamicType
            }, baseExp, selector));
        }