public static QueryableTranslation Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
        {
            var translator = new QueryableTranslator(serializerRegistry);
            translator.Translate(node);

            var model = (QueryableExecutionModel)Activator.CreateInstance(
                typeof(AggregateQueryableExecutionModel<>).MakeGenericType(translator._outputSerializer.ValueType),
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new object[] { translator._stages, translator._outputSerializer },
                null);

            return new QueryableTranslation(model, translator._resultTransformer);
        }
        public static QueryableTranslation Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
        {
            var translator = new QueryableTranslator(serializerRegistry);

            translator.Translate(node);

            var model = (QueryableExecutionModel)Activator.CreateInstance(
                typeof(AggregateQueryableExecutionModel <>).MakeGenericType(translator._outputSerializer.ValueType),
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new object[] { translator._stages, translator._outputSerializer },
                null);

            return(new QueryableTranslation(model, translator._resultTransformer));
        }
示例#3
0
        public static QueryableTranslation Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
        {
            var translator = new QueryableTranslator(serializerRegistry);
            translator.Translate(node);

            var outputType = translator._outputSerializer.ValueType;
            var modelType = typeof(AggregateQueryableExecutionModel<>).MakeGenericType(outputType);
            var modelTypeInfo = modelType.GetTypeInfo();
            var outputSerializerInterfaceType = typeof(IBsonSerializer<>).MakeGenericType(new[] { outputType });
            var constructorParameterTypes = new Type[] { typeof(IEnumerable<BsonDocument>), outputSerializerInterfaceType };
            var constructorInfo = modelTypeInfo.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
                .Where(c => c.GetParameters().Select(p => p.ParameterType).SequenceEqual(constructorParameterTypes))
                .Single();
            var constructorParameters = new object[] { translator._stages, translator._outputSerializer };
            var model = (QueryableExecutionModel)constructorInfo.Invoke(constructorParameters);

            return new QueryableTranslation(model, translator._resultTransformer);
        }
        public static QueryableTranslation Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
        {
            var translator = new QueryableTranslator(serializerRegistry, translationOptions);

            translator.Translate(node);

            var outputType    = translator._outputSerializer.ValueType;
            var modelType     = typeof(AggregateQueryableExecutionModel <>).MakeGenericType(outputType);
            var modelTypeInfo = modelType.GetTypeInfo();
            var outputSerializerInterfaceType = typeof(IBsonSerializer <>).MakeGenericType(new[] { outputType });
            var constructorParameterTypes     = new Type[] { typeof(IEnumerable <BsonDocument>), outputSerializerInterfaceType };
            var constructorInfo = modelTypeInfo.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
                                  .Where(c => c.GetParameters().Select(p => p.ParameterType).SequenceEqual(constructorParameterTypes))
                                  .Single();
            var constructorParameters = new object[] { translator._stages, translator._outputSerializer };
            var model = (QueryableExecutionModel)constructorInfo.Invoke(constructorParameters);

            return(new QueryableTranslation(model, translator._resultTransformer));
        }