// public static methods public static AstFilter Translate(TranslationContext context, MethodCallExpression expression) { var method = expression.Method; var arguments = expression.Arguments; if (method.Is(LinqExtensionsMethod.Inject)) { var filterExpression = arguments[0]; var filterDefinition = filterExpression.GetConstantValue <object>(expression); var filterDefinitionType = filterDefinition.GetType(); // we KNOW it's a FilterDefinition<TDocument> because of the Inject method signature var documentType = filterDefinitionType.GetGenericArguments()[0]; var serializerRegistry = BsonSerializer.SerializerRegistry; var documentSerializer = serializerRegistry.GetSerializer(documentType); // TODO: is this the right serializer? var renderMethodArgumentTypes = new[] { typeof(IBsonSerializer <>).MakeGenericType(documentType), typeof(IBsonSerializerRegistry), typeof(LinqProvider) }; var renderMethod = filterDefinitionType.GetMethod("Render", renderMethodArgumentTypes); var renderedFilter = (BsonDocument)renderMethod.Invoke(filterDefinition, new object[] { documentSerializer, serializerRegistry, LinqProvider.V3 }); return(AstFilter.Raw(renderedFilter)); } throw new ExpressionNotSupportedException(expression); }