internal override RenderedFieldDefinition <TField> TranslateExpressionToField <TDocument, TField>(
            Expression <Func <TDocument, TField> > expression,
            IBsonSerializer <TDocument> documentSerializer,
            IBsonSerializerRegistry serializerRegistry,
            bool allowScalarValueForArrayField)
        {
            var lambda              = (LambdaExpression)PartialEvaluator.Evaluate(expression);
            var bindingContext      = new PipelineBindingContext(serializerRegistry);
            var parameterExpression = new DocumentExpression(documentSerializer);

            bindingContext.AddExpressionMapping(lambda.Parameters[0], parameterExpression);
            var bound = bindingContext.Bind(lambda.Body);

            bound = FieldExpressionFlattener.FlattenFields(bound);
            IFieldExpression field;

            if (!ExpressionHelper.TryGetExpression(bound, out field))
            {
                var message = string.Format("Unable to determine the serialization information for {0}.", expression);
                throw new InvalidOperationException(message);
            }

            var underlyingSerializer = field.Serializer;
            var fieldSerializer      = underlyingSerializer as IBsonSerializer <TField>;
            var valueSerializer      = (IBsonSerializer <TField>)FieldValueSerializerHelper.GetSerializerForValueType(underlyingSerializer, serializerRegistry, typeof(TField), allowScalarValueForArrayField);

            return(new RenderedFieldDefinition <TField>(field.FieldName, fieldSerializer, valueSerializer, underlyingSerializer));
        }
        internal override RenderedFieldDefinition TranslateExpressionToField <TDocument>(
            LambdaExpression expression,
            IBsonSerializer <TDocument> documentSerializer,
            IBsonSerializerRegistry serializerRegistry)
        {
            var bindingContext      = new PipelineBindingContext(serializerRegistry);
            var lambda              = ExpressionHelper.GetLambda(PartialEvaluator.Evaluate(expression));
            var parameterExpression = new DocumentExpression(documentSerializer);

            bindingContext.AddExpressionMapping(lambda.Parameters[0], parameterExpression);
            var bound = bindingContext.Bind(lambda.Body);

            bound = FieldExpressionFlattener.FlattenFields(bound);
            IFieldExpression field;

            if (!ExpressionHelper.TryGetExpression(bound, out field))
            {
                var message = string.Format("Unable to determine the serialization information for {0}.", expression);
                throw new InvalidOperationException(message);
            }

            return(new RenderedFieldDefinition(field.FieldName, field.Serializer));
        }