Skip to content

Commit 95179a1

Browse files
committed
Merge commit
1 parent 45d5593 commit 95179a1

File tree

98 files changed

+3223
-1151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3223
-1151
lines changed

src/MongoDB.Bson/BsonDefaults.cs

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,71 +24,46 @@ namespace MongoDB.Bson
2424
/// </summary>
2525
public static class BsonDefaults
2626
{
27-
// private static fields
28-
private static bool __dynamicArraySerializerWasSet;
29-
private static IBsonSerializer __dynamicArraySerializer;
30-
private static bool __dynamicDocumentSerializerWasSet;
31-
private static IBsonSerializer __dynamicDocumentSerializer;
32-
private static int __maxDocumentSize = int.MaxValue;
33-
private static int __maxSerializationDepth = 100;
34-
3527
// public static properties
3628
/// <summary>
3729
/// Gets or sets the dynamic array serializer.
3830
/// </summary>
3931
public static IBsonSerializer DynamicArraySerializer
4032
{
41-
get
42-
{
43-
if (!__dynamicArraySerializerWasSet)
44-
{
45-
__dynamicArraySerializer = BsonSerializer.LookupSerializer<List<object>>();
46-
}
47-
return __dynamicArraySerializer;
48-
}
49-
set
50-
{
51-
__dynamicArraySerializerWasSet = true;
52-
__dynamicArraySerializer = value;
53-
}
33+
get => BsonSerializationDomain.Default.BsonDefaults.DynamicArraySerializer;
34+
set => BsonSerializationDomain.Default.BsonDefaults.DynamicArraySerializer = value;
5435
}
5536

5637
/// <summary>
5738
/// Gets or sets the dynamic document serializer.
5839
/// </summary>
5940
public static IBsonSerializer DynamicDocumentSerializer
6041
{
61-
get
62-
{
63-
if (!__dynamicDocumentSerializerWasSet)
64-
{
65-
__dynamicDocumentSerializer = BsonSerializer.LookupSerializer<ExpandoObject>();
66-
}
67-
return __dynamicDocumentSerializer;
68-
}
69-
set
70-
{
71-
__dynamicDocumentSerializerWasSet = true;
72-
__dynamicDocumentSerializer = value;
73-
}
42+
get => BsonSerializationDomain.Default.BsonDefaults.DynamicDocumentSerializer;
43+
set => BsonSerializationDomain.Default.BsonDefaults.DynamicDocumentSerializer = value;
7444
}
7545

46+
/* DOMAIN-API We should modify the API to have those two values (and in the writer/reader settings where they are used) be nullable.
47+
* The problem is that we need to now when these values have been set externally or not. If they have not, then they should
48+
* be retrieved from the closest domain.
49+
*/
50+
7651
/// <summary>
7752
/// Gets or sets the default max document size. The default is 4MiB.
7853
/// </summary>
7954
public static int MaxDocumentSize
8055
{
81-
get { return __maxDocumentSize; }
82-
set { __maxDocumentSize = value; }
56+
get => BsonSerializationDomain.Default.BsonDefaults.MaxDocumentSize;
57+
set => BsonSerializationDomain.Default.BsonDefaults.MaxDocumentSize = value;
8358
}
8459

8560
/// <summary>
8661
/// Gets or sets the default max serialization depth (used to detect circular references during serialization). The default is 100.
8762
/// </summary>
8863
public static int MaxSerializationDepth
8964
{
90-
get { return __maxSerializationDepth; }
91-
set { __maxSerializationDepth = value; }
65+
get => BsonSerializationDomain.Default.BsonDefaults.MaxSerializationDepth;
66+
set => BsonSerializationDomain.Default.BsonDefaults.MaxSerializationDepth = value;
9267
}
9368
}
9469
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using System.Dynamic;
18+
using MongoDB.Bson.Serialization;
19+
20+
namespace MongoDB.Bson
21+
{
22+
internal class BsonDefaultsRegistry : IBsonDefaults
23+
{
24+
private IBsonSerializationDomain _serializationDomain;
25+
private bool _dynamicArraySerializerWasSet;
26+
private IBsonSerializer _dynamicArraySerializer;
27+
private bool _dynamicDocumentSerializerWasSet;
28+
private IBsonSerializer _dynamicDocumentSerializer;
29+
30+
public BsonDefaultsRegistry(IBsonSerializationDomain serializationDomain)
31+
{
32+
_serializationDomain = serializationDomain;
33+
}
34+
35+
public IBsonSerializer DynamicArraySerializer
36+
{
37+
get
38+
{
39+
if (!_dynamicArraySerializerWasSet)
40+
{
41+
_dynamicArraySerializer = _serializationDomain.LookupSerializer<List<object>>();
42+
}
43+
return _dynamicArraySerializer;
44+
}
45+
set
46+
{
47+
_dynamicArraySerializerWasSet = true;
48+
_dynamicArraySerializer = value;
49+
}
50+
}
51+
52+
public IBsonSerializer DynamicDocumentSerializer
53+
{
54+
get
55+
{
56+
if (!_dynamicDocumentSerializerWasSet)
57+
{
58+
_dynamicDocumentSerializer = _serializationDomain.LookupSerializer<ExpandoObject>();
59+
}
60+
return _dynamicDocumentSerializer;
61+
}
62+
set
63+
{
64+
_dynamicDocumentSerializerWasSet = true;
65+
_dynamicDocumentSerializer = value;
66+
}
67+
}
68+
69+
public int MaxDocumentSize { get; set; } = int.MaxValue;
70+
71+
public int MaxSerializationDepth { get; set; } = 100;
72+
}
73+
}

src/MongoDB.Bson/BsonExtensionMethods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static byte[] ToBson(
8484

8585
if (serializer == null)
8686
{
87-
serializer = BsonSerializer.LookupSerializer(nominalType);
87+
serializer = BsonSerializationDomain.Default.LookupSerializer(nominalType);
8888
}
8989
if (serializer.ValueType != nominalType)
9090
{
@@ -165,7 +165,7 @@ public static BsonDocument ToBsonDocument(
165165
return convertibleToBsonDocument.ToBsonDocument(); // use the provided ToBsonDocument method
166166
}
167167

168-
serializer = BsonSerializer.LookupSerializer(nominalType);
168+
serializer = BsonSerializationDomain.Default.LookupSerializer(nominalType);
169169
}
170170
if (serializer.ValueType != nominalType)
171171
{
@@ -236,7 +236,7 @@ public static string ToJson(
236236

237237
if (serializer == null)
238238
{
239-
serializer = BsonSerializer.LookupSerializer(nominalType);
239+
serializer = BsonSerializationDomain.Default.LookupSerializer(nominalType);
240240
}
241241
if (serializer.ValueType != nominalType)
242242
{

src/MongoDB.Bson/IBsonDefaults.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using MongoDB.Bson.Serialization;
17+
18+
namespace MongoDB.Bson
19+
{
20+
internal interface IBsonDefaults
21+
{
22+
/// <summary>
23+
///
24+
/// </summary>
25+
IBsonSerializer DynamicArraySerializer { get; set; }
26+
/// <summary>
27+
///
28+
/// </summary>
29+
IBsonSerializer DynamicDocumentSerializer { get; set; }
30+
/// <summary>
31+
///
32+
/// </summary>
33+
int MaxDocumentSize { get; set; }
34+
/// <summary>
35+
///
36+
/// </summary>
37+
int MaxSerializationDepth { get; set; }
38+
}
39+
}

src/MongoDB.Bson/IO/BsonBinaryReaderSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Text;
18+
using MongoDB.Bson.Serialization;
1819

1920
namespace MongoDB.Bson.IO
2021
{
@@ -30,7 +31,7 @@ public class BsonBinaryReaderSettings : BsonReaderSettings
3031
private UTF8Encoding _encoding = Utf8Encodings.Strict;
3132
private bool _fixOldBinarySubTypeOnInput = true;
3233
private bool _fixOldDateTimeMaxValueOnInput = true;
33-
private int _maxDocumentSize = BsonDefaults.MaxDocumentSize;
34+
private int _maxDocumentSize = BsonSerializationDomain.Default.BsonDefaults.MaxDocumentSize;
3435

3536
// constructors
3637
/// <summary>

src/MongoDB.Bson/IO/BsonBinaryWriterSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Text;
18+
using MongoDB.Bson.Serialization;
1819

1920
namespace MongoDB.Bson.IO
2021
{
@@ -29,7 +30,7 @@ public class BsonBinaryWriterSettings : BsonWriterSettings
2930
// private fields
3031
private UTF8Encoding _encoding = Utf8Encodings.Strict;
3132
private bool _fixOldBinarySubTypeOnOutput = true;
32-
private int _maxDocumentSize = BsonDefaults.MaxDocumentSize;
33+
private int _maxDocumentSize = BsonSerializationDomain.Default.BsonDefaults.MaxDocumentSize;
3334

3435
// constructors
3536
/// <summary>

src/MongoDB.Bson/IO/BsonWriterSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System;
17+
using MongoDB.Bson.Serialization;
1718

1819
namespace MongoDB.Bson.IO
1920
{
@@ -24,7 +25,7 @@ public abstract class BsonWriterSettings
2425
{
2526
// private fields
2627
private bool _isFrozen;
27-
private int _maxSerializationDepth = BsonDefaults.MaxSerializationDepth;
28+
private int _maxSerializationDepth = BsonSerializationDomain.Default.BsonDefaults.MaxSerializationDepth;
2829

2930
// constructors
3031
/// <summary>

src/MongoDB.Bson/ObjectModel/BsonDocumentWrapper.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ public static BsonDocumentWrapper Create<TNominalType>(TNominalType value)
104104
/// <returns>A BsonDocumentWrapper.</returns>
105105
public static BsonDocumentWrapper Create(Type nominalType, object value)
106106
{
107-
var serializer = BsonSerializer.LookupSerializer(nominalType);
107+
return Create(BsonSerializationDomain.Default, nominalType, value);
108+
}
109+
110+
internal static BsonDocumentWrapper Create(IBsonSerializationDomain serializationDomain, Type nominalType, object value)
111+
{
112+
var serializer = serializationDomain.LookupSerializer(nominalType);
108113
return new BsonDocumentWrapper(value, serializer);
109114
}
110115

@@ -116,12 +121,21 @@ public static BsonDocumentWrapper Create(Type nominalType, object value)
116121
/// <returns>A list of BsonDocumentWrappers.</returns>
117122
public static IEnumerable<BsonDocumentWrapper> CreateMultiple<TNominalType>(IEnumerable<TNominalType> values)
118123
{
124+
return CreateMultiple(BsonSerializationDomain.Default, values);
125+
}
126+
127+
internal static IEnumerable<BsonDocumentWrapper> CreateMultiple<TNominalType>(IBsonSerializationDomain serializationDomain, IEnumerable<TNominalType> values)
128+
{
129+
if (serializationDomain == null)
130+
{
131+
throw new ArgumentNullException("serializationDomain");
132+
}
119133
if (values == null)
120134
{
121135
throw new ArgumentNullException("values");
122136
}
123137

124-
var serializer = BsonSerializer.LookupSerializer(typeof(TNominalType));
138+
var serializer = serializationDomain.LookupSerializer(typeof(TNominalType));
125139
return values.Select(v => new BsonDocumentWrapper(v, serializer));
126140
}
127141

@@ -132,6 +146,11 @@ public static IEnumerable<BsonDocumentWrapper> CreateMultiple<TNominalType>(IEnu
132146
/// <param name="values">A list of wrapped objects.</param>
133147
/// <returns>A list of BsonDocumentWrappers.</returns>
134148
public static IEnumerable<BsonDocumentWrapper> CreateMultiple(Type nominalType, IEnumerable values)
149+
{
150+
return CreateMultiple(BsonSerializationDomain.Default, nominalType, values);
151+
}
152+
153+
internal static IEnumerable<BsonDocumentWrapper> CreateMultiple(IBsonSerializationDomain serializationDomain, Type nominalType, IEnumerable values)
135154
{
136155
if (nominalType == null)
137156
{
@@ -142,7 +161,7 @@ public static IEnumerable<BsonDocumentWrapper> CreateMultiple(Type nominalType,
142161
throw new ArgumentNullException("values");
143162
}
144163

145-
var serializer = BsonSerializer.LookupSerializer(nominalType);
164+
var serializer = serializationDomain.LookupSerializer(nominalType);
146165
return values.Cast<object>().Select(v => new BsonDocumentWrapper(v, serializer));
147166
}
148167

src/MongoDB.Bson/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@
2828

2929
[assembly: InternalsVisibleTo("MongoDB.Bson.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010035287f0d3883c0a075c88e0cda3ce93b621003ecbd5e920d4a8c7238564f4d2f4f68116aca28c9b21341dc3a877679c14556192b2b2f5fe2c11d624e0894d308ff7b94bf6fd72aef1b41017ffe2572e99019d1c61963e68cd0ed67734a42cb333b808e3867cbe631937214e32e409fb1fa62fdb69d494c2530e64a40e417d6ee")]
3030
[assembly: InternalsVisibleTo("MongoDB.Analyzer.MQLGenerator, PublicKey=002400000480000094000000060200000024000052534131000400000100010035287f0d3883c0a075c88e0cda3ce93b621003ecbd5e920d4a8c7238564f4d2f4f68116aca28c9b21341dc3a877679c14556192b2b2f5fe2c11d624e0894d308ff7b94bf6fd72aef1b41017ffe2572e99019d1c61963e68cd0ed67734a42cb333b808e3867cbe631937214e32e409fb1fa62fdb69d494c2530e64a40e417d6ee")]
31+
[assembly: InternalsVisibleTo("MongoDB.Driver, PublicKey=002400000480000094000000060200000024000052534131000400000100010035287f0d3883c0a075c88e0cda3ce93b621003ecbd5e920d4a8c7238564f4d2f4f68116aca28c9b21341dc3a877679c14556192b2b2f5fe2c11d624e0894d308ff7b94bf6fd72aef1b41017ffe2572e99019d1c61963e68cd0ed67734a42cb333b808e3867cbe631937214e32e409fb1fa62fdb69d494c2530e64a40e417d6ee")]
32+
[assembly: InternalsVisibleTo("MongoDB.Driver.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010035287f0d3883c0a075c88e0cda3ce93b621003ecbd5e920d4a8c7238564f4d2f4f68116aca28c9b21341dc3a877679c14556192b2b2f5fe2c11d624e0894d308ff7b94bf6fd72aef1b41017ffe2572e99019d1c61963e68cd0ed67734a42cb333b808e3867cbe631937214e32e409fb1fa62fdb69d494c2530e64a40e417d6ee")]
33+
[assembly: InternalsVisibleTo("MongoDB.Driver.Encryption, PublicKey=002400000480000094000000060200000024000052534131000400000100010035287f0d3883c0a075c88e0cda3ce93b621003ecbd5e920d4a8c7238564f4d2f4f68116aca28c9b21341dc3a877679c14556192b2b2f5fe2c11d624e0894d308ff7b94bf6fd72aef1b41017ffe2572e99019d1c61963e68cd0ed67734a42cb333b808e3867cbe631937214e32e409fb1fa62fdb69d494c2530e64a40e417d6ee")]
34+
[assembly: InternalsVisibleTo("MongoDB.Driver.Authentication.AWS, PublicKey=002400000480000094000000060200000024000052534131000400000100010035287f0d3883c0a075c88e0cda3ce93b621003ecbd5e920d4a8c7238564f4d2f4f68116aca28c9b21341dc3a877679c14556192b2b2f5fe2c11d624e0894d308ff7b94bf6fd72aef1b41017ffe2572e99019d1c61963e68cd0ed67734a42cb333b808e3867cbe631937214e32e409fb1fa62fdb69d494c2530e64a40e417d6ee")]
35+
[assembly: InternalsVisibleTo("MongoDB.Driver.TestHelpers, PublicKey=002400000480000094000000060200000024000052534131000400000100010035287f0d3883c0a075c88e0cda3ce93b621003ecbd5e920d4a8c7238564f4d2f4f68116aca28c9b21341dc3a877679c14556192b2b2f5fe2c11d624e0894d308ff7b94bf6fd72aef1b41017ffe2572e99019d1c61963e68cd0ed67734a42cb333b808e3867cbe631937214e32e409fb1fa62fdb69d494c2530e64a40e417d6ee")]

0 commit comments

Comments
 (0)