Example #1
0
        public static Expression CreateNewExpression(Expression currentContext, IEnumerable <IGraphQLNode> fieldExpressions, ISchemaProvider schemaProvider, out Type dynamicType)
        {
            var fieldExpressionsByName = fieldExpressions.ToDictionary(f => f.Name, f => f.NodeExpression);

            dynamicType = LinqRuntimeTypeBuilder.GetDynamicType(fieldExpressions.ToDictionary(f => f.Name, f => f.NodeExpression.Type));

            var bindings = dynamicType.GetFields().Select(p => Expression.Bind(p, fieldExpressionsByName[p.Name])).OfType <MemberBinding>();
            var newExp   = Expression.New(dynamicType.GetConstructor(Type.EmptyTypes));
            var mi       = Expression.MemberInit(newExp, bindings);

            return(mi);
        }
Example #2
0
        private static Expression CreateNewExpression(Expression currentContext, IEnumerable <IGraphQLNode> fieldExpressions, ISchemaProvider schemaProvider, out Type dynamicType)
        {
            var fieldExpressionsByName = new Dictionary <String, ExpressionResult>();

            foreach (var item in fieldExpressions)
            {
                // if there are dupelicate fields (looking at you ApolloClient when using fragments) they override
                fieldExpressionsByName[item.Name] = item.GetNodeExpression();
            }
            dynamicType = LinqRuntimeTypeBuilder.GetDynamicType(fieldExpressionsByName.ToDictionary(f => f.Key, f => f.Value.Type));

            var bindings = dynamicType.GetFields().Select(p => Expression.Bind(p, fieldExpressionsByName[p.Name])).OfType <MemberBinding>();
            var newExp   = Expression.New(dynamicType.GetConstructor(Type.EmptyTypes));
            var mi       = Expression.MemberInit(newExp, bindings);

            return(mi);
        }
Example #3
0
        private static Expression CreateNewExpression(Dictionary <string, ExpressionResult> fieldExpressions)
        {
            var fieldExpressionsByName = new Dictionary <string, ExpressionResult>();

            foreach (var item in fieldExpressions)
            {
                // if there are duplicate fields (looking at you ApolloClient when using fragments) they override
                fieldExpressionsByName[item.Key] = item.Value;
            }
            var dynamicType = LinqRuntimeTypeBuilder.GetDynamicType(fieldExpressionsByName.ToDictionary(f => f.Key, f => f.Value.Type));

            var bindings = dynamicType.GetFields().Select(p => Expression.Bind(p, fieldExpressionsByName[p.Name])).OfType <MemberBinding>();
            var newExp   = Expression.New(dynamicType.GetConstructor(Type.EmptyTypes));
            var mi       = Expression.MemberInit(newExp, bindings);

            return(mi);
        }