-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-3985: Serialization config objects belong to a serialization domain #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0472c3d
0595cb8
d83811d
ef988c3
879f6c5
43ea9c2
08247aa
a8ba088
59c3a47
27671ae
f8915ab
7f45484
acd8a64
a541b08
76665ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* Copyright 2010-present MongoDB Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Dynamic; | ||
| using MongoDB.Bson.Serialization; | ||
|
|
||
| namespace MongoDB.Bson | ||
| { | ||
| internal class BsonDefaultsRegistry : IBsonDefaults | ||
| { | ||
| private IBsonSerializationDomain _serializationDomain; | ||
| private bool _dynamicArraySerializerWasSet; | ||
| private IBsonSerializer _dynamicArraySerializer; | ||
| private bool _dynamicDocumentSerializerWasSet; | ||
| private IBsonSerializer _dynamicDocumentSerializer; | ||
|
|
||
| public BsonDefaultsRegistry(IBsonSerializationDomain serializationDomain) | ||
| { | ||
| _serializationDomain = serializationDomain; | ||
| } | ||
|
|
||
| public IBsonSerializer DynamicArraySerializer | ||
| { | ||
| get | ||
| { | ||
| if (!_dynamicArraySerializerWasSet) | ||
| { | ||
| _dynamicArraySerializer = _serializationDomain.LookupSerializer<List<object>>(); | ||
| } | ||
| return _dynamicArraySerializer; | ||
| } | ||
| set | ||
| { | ||
| _dynamicArraySerializerWasSet = true; | ||
| _dynamicArraySerializer = value; | ||
| } | ||
| } | ||
|
|
||
| public IBsonSerializer DynamicDocumentSerializer | ||
| { | ||
| get | ||
| { | ||
| if (!_dynamicDocumentSerializerWasSet) | ||
| { | ||
| _dynamicDocumentSerializer = _serializationDomain.LookupSerializer<ExpandoObject>(); | ||
| } | ||
| return _dynamicDocumentSerializer; | ||
| } | ||
| set | ||
| { | ||
| _dynamicDocumentSerializerWasSet = true; | ||
| _dynamicDocumentSerializer = value; | ||
| } | ||
| } | ||
|
|
||
| public int MaxDocumentSize { get; set; } = int.MaxValue; | ||
|
|
||
| public int MaxSerializationDepth { get; set; } = 100; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* Copyright 2010-present MongoDB Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| using MongoDB.Bson.Serialization; | ||
|
|
||
| namespace MongoDB.Bson | ||
| { | ||
| internal interface IBsonDefaults | ||
| { | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| IBsonSerializer DynamicArraySerializer { get; set; } | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| IBsonSerializer DynamicDocumentSerializer { get; set; } | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| int MaxDocumentSize { get; set; } | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| int MaxSerializationDepth { get; set; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| using System; | ||
| using System.Text; | ||
| using MongoDB.Bson.Serialization; | ||
|
|
||
| namespace MongoDB.Bson.IO | ||
| { | ||
|
|
@@ -30,7 +31,7 @@ public class BsonBinaryReaderSettings : BsonReaderSettings | |
| private UTF8Encoding _encoding = Utf8Encodings.Strict; | ||
| private bool _fixOldBinarySubTypeOnInput = true; | ||
| private bool _fixOldDateTimeMaxValueOnInput = true; | ||
| private int _maxDocumentSize = BsonDefaults.MaxDocumentSize; | ||
| private int _maxDocumentSize = BsonSerializationDomain.Default.BsonDefaults.MaxDocumentSize; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can we inject the domain here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not bother to put The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We got 4 properties in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I wouldn't remove it entirely though. We need a limit to prevent infinite recursion if someone attempts to serialize a circular structure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree we can't simply remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually unclear how these properties are used... but it does look like they could be configured in either the |
||
|
|
||
| // constructors | ||
| /// <summary> | ||
|
|
||