Skip to content

Commit 2f8e417

Browse files
committed
Removed references to certain parts of BsonDefaults.
1 parent 48af503 commit 2f8e417

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

src/MongoDB.Bson/BsonDefaults.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public static IBsonSerializer DynamicDocumentSerializer
4343
set => BsonSerializer.DefaultSerializationDomain.BsonDefaults.DynamicDocumentSerializer = value;
4444
}
4545

46+
/* QUESTION How do we do with those two? I don't think I can remove references to them without breaking public API.
47+
* We should modify the API to have those two values (in the writer/reader settings where they are used) be nullable.
48+
* The problem is that we need to now when these values have been set externally or not. If they have not, then they should
49+
* be retrieved from the closest domain. We could use a negative sentinel value for that, but that would not be the best.
50+
*/
51+
4652
/// <summary>
4753
/// Gets or sets the default max document size. The default is 4MiB.
4854
/// </summary>

src/MongoDB.Bson/BsonDefaultsDomain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace MongoDB.Bson
2121
{
22-
internal class BsonDefaultsDomain : IBsonDefaults //TODO This will need to be public at a later point
22+
internal class BsonDefaultsDomain : IBsonDefaults
2323
{
2424
private IBsonSerializationDomain _serializationDomain;
2525
private bool _dynamicArraySerializerWasSet;

src/MongoDB.Bson/Serialization/BsonDeserializationContext.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ private BsonDeserializationContext(
4848
}
4949

5050
_serializationDomain ??= BsonSerializer.DefaultSerializationDomain;
51+
52+
_dynamicArraySerializer ??= _serializationDomain.BsonDefaults.DynamicArraySerializer;
53+
_dynamicDocumentSerializer ??= _serializationDomain.BsonDefaults.DynamicDocumentSerializer;
5154
}
5255

5356
// public properties
@@ -167,11 +170,10 @@ internal Builder(BsonDeserializationContext other, IBsonReader reader)
167170
_dynamicArraySerializer = other.DynamicArraySerializer;
168171
_dynamicDocumentSerializer = other.DynamicDocumentSerializer;
169172
}
170-
else
171-
{
172-
_dynamicArraySerializer = BsonDefaults.DynamicArraySerializer;
173-
_dynamicDocumentSerializer = BsonDefaults.DynamicDocumentSerializer;
174-
}
173+
174+
/* QUESTION I removed the part where we set the dynamic serializers from the BsonDefaults, and delay it until we have a serialization domain (when we build the DeserializationContext).
175+
* This is technically changing the public behaviour, but it's in a builder, I do not thing it will affect anyone. Same done for the serialization context.
176+
*/
175177
}
176178

177179
// properties

src/MongoDB.Bson/Serialization/BsonSerializationContext.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ private BsonSerializationContext(
3636
_writer = writer;
3737
_isDynamicType = isDynamicType;
3838
_serializationDomain = writer.Settings?.SerializationDomain ?? BsonSerializer.DefaultSerializationDomain;
39+
40+
_isDynamicType??= t =>
41+
(_serializationDomain.BsonDefaults.DynamicArraySerializer != null && t == _serializationDomain.BsonDefaults.DynamicArraySerializer.ValueType) ||
42+
(_serializationDomain.BsonDefaults.DynamicDocumentSerializer != null && t == _serializationDomain.BsonDefaults.DynamicDocumentSerializer.ValueType);
3943
}
4044

4145
// public properties
@@ -126,12 +130,10 @@ internal Builder(BsonSerializationContext other, IBsonWriter writer)
126130
{
127131
_isDynamicType = other._isDynamicType;
128132
}
129-
else
130-
{
131-
_isDynamicType = t =>
132-
(BsonDefaults.DynamicArraySerializer != null && t == BsonDefaults.DynamicArraySerializer.ValueType) ||
133-
(BsonDefaults.DynamicDocumentSerializer != null && t == BsonDefaults.DynamicDocumentSerializer.ValueType);
134-
}
133+
134+
/* QUESTION I removed the part where we set _isDynamicType from the BsonDefaults, and delay it until we have a serialization domain (when we build the SerializationContext).
135+
* This is technically changing the public behaviour, but it's in a builder, I do not thing it will affect anyone. Same done for the deserialization context.
136+
*/
135137
}
136138

137139
// properties

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;
66+
_serializerRegistry = BsonSerializer.SerializerRegistry; //FP This needs to go
6767
var serializationContext = BsonSerializationContext.CreateRoot(binaryWriter);
6868
_idsMap = section.IdsMap;
6969
var stream = binaryWriter.BsonStream;

0 commit comments

Comments
 (0)