Skip to content

Commit 7f5ed7a

Browse files
committed
Various fixes
1 parent 2f8e417 commit 7f5ed7a

File tree

17 files changed

+42
-47
lines changed

17 files changed

+42
-47
lines changed

src/MongoDB.Bson/Serialization/BsonClassMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public IEnumerable<BsonCreatorMap> CreatorMaps
122122
/// </summary>
123123
public IConventionPack ConventionPack
124124
{
125-
get { return BsonSerializer.DefaultSerializationDomain.ConventionRegistry.Lookup(_classType); } //TODO This is not completely correct, this should be eliminated.
125+
get { return BsonSerializer.DefaultSerializationDomain.ConventionRegistry.Lookup(_classType); }
126126
}
127127

128128
/// <summary>

src/MongoDB.Bson/Serialization/BsonMemberMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public BsonMemberMap(BsonClassMap classMap, MemberInfo memberInfo)
5656
{
5757
_classMap = classMap;
5858
_memberInfo = memberInfo;
59-
_memberType = BsonClassMap.GetMemberInfoType(memberInfo);
59+
_memberType = BsonClassMap.GetMemberInfoType(memberInfo); //FP This is more of a utility method, it can stay like this
6060
_memberTypeIsBsonValue = typeof(BsonValue).GetTypeInfo().IsAssignableFrom(_memberType);
6161

6262
Reset();

src/MongoDB.Driver/Core/Operations/RetryableInsertCommandOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public override void Serialize(BsonSerializationContext context, BsonSerializati
139139
{
140140
if (_cachedSerializer.ValueType != actualType)
141141
{
142-
_cachedSerializer = BsonSerializer.LookupSerializer(actualType);
142+
_cachedSerializer = BsonSerializer.LookupSerializer(actualType); //FP This needs to go, need to access MongoDB.Bson internals to access domain
143143
}
144144
serializer = _cachedSerializer;
145145
}

src/MongoDB.Driver/Core/WireProtocol/Messages/Encoders/BinaryEncoders/ClientBulkWriteOpsSectionFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void FormatSection(ClientBulkWriteOpsCommandMessageSection section, IBson
6363
throw new ArgumentException("Writer must be an instance of BsonBinaryWriter.");
6464
}
6565

66-
_serializerRegistry = BsonSerializer.SerializerRegistry; //FP This needs to go
66+
_serializerRegistry = BsonSerializer.SerializerRegistry; //FP This needs to go, need to access MongoDB.Bson internals to access domain
6767
var serializationContext = BsonSerializationContext.CreateRoot(binaryWriter);
6868
_idsMap = section.IdsMap;
6969
var stream = binaryWriter.BsonStream;

src/MongoDB.Driver/FieldValueSerializerHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static IBsonSerializer GetSerializerForValueType(IBsonSerializer fieldSer
5151
// serialize numeric values without converting them
5252
if (fieldType.IsNumeric() && valueType.IsNumeric())
5353
{
54-
var valueSerializer = BsonSerializer.SerializerRegistry.GetSerializer(valueType);
54+
var valueSerializer = BsonSerializer.SerializerRegistry.GetSerializer(valueType); //QUESTION What to we do here? We don't even use the input serializer registry. Probably ask Robert
5555
if (HasStringRepresentation(fieldSerializer))
5656
{
5757
valueSerializer = WithStringRepresentation(valueSerializer);

src/MongoDB.Driver/GeoJsonObjectModel/Serializers/GeoJsonPolygonSerializer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ private static class Flags
3232

3333
// private fields
3434
private readonly IBsonSerializer<GeoJsonPolygonCoordinates<TCoordinates>> _coordinatesSerializer = BsonSerializer.LookupSerializer<GeoJsonPolygonCoordinates<TCoordinates>>();
35+
//QUESTION This happens in all GeoJsonOBjectModel serializers, what do we do here? Do we just lookup the serialzer in each Serialize/Deserialize or do we cache it?
3536
private readonly GeoJsonObjectSerializerHelper<TCoordinates> _helper;
3637

3738
// constructors

src/MongoDB.Driver/GridFS/GridFSBucketOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public ReadPreference ReadPreference
243243
/// </value>
244244
public IBsonSerializerRegistry SerializerRegistry
245245
{
246-
get { return BsonSerializer.SerializerRegistry; } //TODO This is wrong
246+
get { return BsonSerializer.SerializerRegistry; } //QUESTION What do we do in this case...? Given it's read only, we could ignore it? Also, why the immutable options have a serializer registry and the non-immutable options do not?
247247
}
248248

249249
/// <summary>

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ArrayLengthExpressionToAggregationExpressionTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static TranslatedExpression Translate(TranslationContext context, UnaryEx
2828
var arrayExpression = expression.Operand;
2929
var arrayTranslation = ExpressionToAggregationExpressionTranslator.TranslateEnumerable(context, arrayExpression);
3030
var ast = AstExpression.Size(arrayTranslation.Ast);
31-
var serializer = BsonSerializer.LookupSerializer(expression.Type);
31+
var serializer = context.SerializationDomain.LookupSerializer(expression.Type);
3232
return new TranslatedExpression(expression, ast, serializer);
3333
}
3434

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ConvertExpressionToAggregationExpressionTranslator.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ sourceExpression is UnaryExpression unarySourceExpression &&
4444
}
4545

4646
var sourceTranslation = ExpressionToAggregationExpressionTranslator.Translate(context, sourceExpression);
47-
return Translate(expression, sourceType, targetType, sourceTranslation);
47+
return Translate(expression, sourceType, targetType, sourceTranslation, context.SerializationDomain);
4848
}
4949

5050
throw new ExpressionNotSupportedException(expression);
5151
}
5252

53-
private static TranslatedExpression Translate(UnaryExpression expression, Type sourceType, Type targetType, TranslatedExpression sourceTranslation)
53+
private static TranslatedExpression Translate(UnaryExpression expression, Type sourceType, Type targetType, TranslatedExpression sourceTranslation, IBsonSerializationDomain serializationDomain)
5454
{
5555
if (targetType == sourceType)
5656
{
@@ -60,12 +60,12 @@ private static TranslatedExpression Translate(UnaryExpression expression, Type s
6060
// from Nullable<T> must be handled before to Nullable<T>
6161
if (IsConvertFromNullableType(sourceType))
6262
{
63-
return TranslateConvertFromNullableType(expression, sourceType, targetType, sourceTranslation);
63+
return TranslateConvertFromNullableType(expression, sourceType, targetType, sourceTranslation, serializationDomain);
6464
}
6565

6666
if (IsConvertToNullableType(targetType))
6767
{
68-
return TranslateConvertToNullableType(expression, sourceType, targetType, sourceTranslation);
68+
return TranslateConvertToNullableType(expression, sourceType, targetType, sourceTranslation, serializationDomain);
6969
}
7070

7171
// from here on we know there are no longer any Nullable<T> types involved
@@ -97,7 +97,7 @@ private static TranslatedExpression Translate(UnaryExpression expression, Type s
9797

9898
if (IsConvertToDerivedType(sourceType, targetType))
9999
{
100-
return TranslateConvertToDerivedType(expression, targetType, sourceTranslation);
100+
return TranslateConvertToDerivedType(expression, targetType, sourceTranslation, serializationDomain);
101101
}
102102

103103
var ast = sourceTranslation.Ast;
@@ -177,10 +177,9 @@ private static TranslatedExpression TranslateConvertToBaseType(UnaryExpression e
177177
return new TranslatedExpression(expression, sourceTranslation.Ast, downcastingSerializer);
178178
}
179179

180-
private static TranslatedExpression TranslateConvertToDerivedType(UnaryExpression expression, Type targetType, TranslatedExpression sourceTranslation)
180+
private static TranslatedExpression TranslateConvertToDerivedType(UnaryExpression expression, Type targetType, TranslatedExpression sourceTranslation, IBsonSerializationDomain serializationDomain)
181181
{
182-
var serializer = BsonSerializer.LookupSerializer(targetType);
183-
182+
var serializer = serializationDomain.LookupSerializer(targetType);
184183
return new TranslatedExpression(expression, sourceTranslation.Ast, serializer);
185184
}
186185

@@ -218,15 +217,15 @@ private static TranslatedExpression TranslateConvertEnumToUnderlyingType(UnaryEx
218217
return new TranslatedExpression(expression, sourceTranslation.Ast, targetSerializer);
219218
}
220219

221-
private static TranslatedExpression TranslateConvertFromNullableType(UnaryExpression expression, Type sourceType, Type targetType, TranslatedExpression sourceTranslation)
220+
private static TranslatedExpression TranslateConvertFromNullableType(UnaryExpression expression, Type sourceType, Type targetType, TranslatedExpression sourceTranslation, IBsonSerializationDomain serializationDomain)
222221
{
223222
if (sourceType.IsNullable(out var sourceValueType))
224223
{
225224
var (sourceVarBinding, sourceAst) = AstExpression.UseVarIfNotSimple("source", sourceTranslation.Ast);
226225
var sourceNullableSerializer = (INullableSerializer)sourceTranslation.Serializer;
227226
var sourceValueSerializer = sourceNullableSerializer.ValueSerializer;
228227
var sourceValueTranslation = new TranslatedExpression(expression.Operand, sourceAst, sourceValueSerializer);
229-
var convertTranslation = Translate(expression, sourceValueType, targetType, sourceValueTranslation);
228+
var convertTranslation = Translate(expression, sourceValueType, targetType, sourceValueTranslation, serializationDomain);
230229

231230
// note: we would have liked to throw a query execution error here if the value is null and the target type is not nullable but there is no way to do that in MQL
232231
// so we just return null instead and the user must check for null themselves if they want to define what happens when the value is null
@@ -242,7 +241,7 @@ private static TranslatedExpression TranslateConvertFromNullableType(UnaryExpres
242241
throw new ExpressionNotSupportedException(expression, because: "sourceType is not nullable");
243242
}
244243

245-
private static TranslatedExpression TranslateConvertToNullableType(UnaryExpression expression, Type sourceType, Type targetType, TranslatedExpression sourceTranslation)
244+
private static TranslatedExpression TranslateConvertToNullableType(UnaryExpression expression, Type sourceType, Type targetType, TranslatedExpression sourceTranslation, IBsonSerializationDomain serializationDomain)
246245
{
247246
if (sourceType.IsNullable())
248247
{
@@ -252,7 +251,7 @@ private static TranslatedExpression TranslateConvertToNullableType(UnaryExpressi
252251

253252
if (targetType.IsNullable(out var targetValueType))
254253
{
255-
var convertTranslation = Translate(expression, sourceType, targetValueType, sourceTranslation);
254+
var convertTranslation = Translate(expression, sourceType, targetValueType, sourceTranslation, serializationDomain);
256255
var nullableSerializer = NullableSerializer.Create(convertTranslation.Serializer);
257256
return new TranslatedExpression(expression, convertTranslation.Ast, nullableSerializer);
258257
}

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OfTypeMethodToAggregationExpressionTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static TranslatedExpression Translate(TranslationContext context, MethodC
5656
var nominalType = itemSerializer.ValueType;
5757
var nominalTypeSerializer = itemSerializer;
5858
var actualType = method.GetGenericArguments().Single();
59-
var actualTypeSerializer = BsonSerializer.LookupSerializer(actualType);
59+
var actualTypeSerializer = context.SerializationDomain.LookupSerializer(actualType);
6060

6161
AstExpression ast;
6262
if (nominalType == actualType)

0 commit comments

Comments
 (0)