Skip to content

Commit 3a2b361

Browse files
committed
Hide IBsonReader settings
1 parent 1791906 commit 3a2b361

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/MongoDB.Bson/IO/IBsonReader.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public interface IBsonReader : IDisposable
6262
/// <summary>
6363
/// Pops the settings.
6464
/// </summary>
65-
void PopSettings(); //TODO Why do we have push and pop methods? They are not used. We should remove them.
65+
void PopSettings(); //TODO Why do we have push and pop methods? They are not used. We should remove them.
6666

6767
/// <summary>
6868
/// Pushes new settings for the reader.
@@ -246,14 +246,6 @@ public interface IBsonReader : IDisposable
246246
/// <param name="bookmark">The bookmark.</param>
247247
void ReturnToBookmark(BsonReaderBookmark bookmark);
248248

249-
//TODO I'm not sure why this was not already present, there is already an equivalent in IBsonWriter.
250-
//We can also avoid adding this to the interface and casting all the occurrences of IBsonReader to BsonReader (the base class for all readers in our codebase).
251-
//Of course this would be a problem if someone implements IBsonReader in a different way.
252-
/// <summary>
253-
/// Gets the settings of the reader.
254-
/// </summary>
255-
BsonReaderSettings Settings { get; }
256-
257249
/// <summary>
258250
/// Skips the name (reader must be positioned on a name).
259251
/// </summary>
@@ -264,4 +256,13 @@ public interface IBsonReader : IDisposable
264256
/// </summary>
265257
void SkipValue();
266258
}
259+
260+
internal interface IBsonReaderInternal : IBsonReader
261+
{
262+
//TODO I'm not sure why this was not already present, there is already an equivalent in IBsonWriter.
263+
/// <summary>
264+
/// Gets the settings of the reader.
265+
/// </summary>
266+
BsonReaderSettings Settings { get; }
267+
}
267268
}

src/MongoDB.Bson/Serialization/BsonDeserializationContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ private BsonDeserializationContext(
4141
_allowDuplicateElementNames = allowDuplicateElementNames;
4242
_dynamicArraySerializer = dynamicArraySerializer;
4343
_dynamicDocumentSerializer = dynamicDocumentSerializer;
44-
_serializationDomain = reader.Settings?.SerializationDomain ?? BsonSerializer.DefaultSerializationDomain;
44+
45+
if (reader is IBsonReaderInternal readerInternal)
46+
{
47+
_serializationDomain = readerInternal.Settings?.SerializationDomain;
48+
}
49+
50+
_serializationDomain ??= BsonSerializer.DefaultSerializationDomain;
4551
}
4652

4753
// public properties

0 commit comments

Comments
 (0)