diff --git a/src/MongoDB.Bson/MongoDB.Bson.csproj b/src/MongoDB.Bson/MongoDB.Bson.csproj
index 6b88210e189..71ffb458fa9 100644
--- a/src/MongoDB.Bson/MongoDB.Bson.csproj
+++ b/src/MongoDB.Bson/MongoDB.Bson.csproj
@@ -20,7 +20,9 @@
-
+
+
+
diff --git a/src/MongoDB.Bson/Serialization/BsonClassMap.cs b/src/MongoDB.Bson/Serialization/BsonClassMap.cs
index 61695ad3966..daedccbdbe3 100644
--- a/src/MongoDB.Bson/Serialization/BsonClassMap.cs
+++ b/src/MongoDB.Bson/Serialization/BsonClassMap.cs
@@ -19,10 +19,10 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization.Conventions;
+using MongoDB.Shared;
namespace MongoDB.Bson.Serialization
{
@@ -542,6 +542,35 @@ public object CreateInstance()
return creator.Invoke();
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ GetType().Equals(obj.GetType()) &&
+ obj is BsonClassMap other &&
+ _frozen.Equals(true) && other._frozen.Equals(true) && // BsonClassMaps should only be equal if they are frozen
+ object.Equals(_baseClassMap, other._baseClassMap) &&
+ object.Equals(_classType, other._classType) &&
+ object.Equals(_creator, other._creator) &&
+ SequenceComparer.Equals(_creatorMaps, other._creatorMaps) &&
+ SequenceComparer.Equals(_declaredMemberMaps, other._declaredMemberMaps) &&
+ object.Equals(_discriminator, other._discriminator) &&
+ _discriminatorIsRequired.Equals(other._discriminatorIsRequired) &&
+ _extraElementsMemberIndex.Equals(other._extraElementsMemberIndex) &&
+ object.Equals(_extraElementsMemberMap, other._extraElementsMemberMap) &&
+ _hasRootClass.Equals(other._hasRootClass) &&
+ object.Equals(_idMemberMap, other._idMemberMap) &&
+ _ignoreExtraElements.Equals(other._ignoreExtraElements) &&
+ _ignoreExtraElementsIsInherited.Equals(other._ignoreExtraElementsIsInherited) &&
+ _isRootClass.Equals(other._isRootClass) &&
+ SequenceComparer.Equals(_knownTypes, other._knownTypes);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Freezes the class map.
///
diff --git a/src/MongoDB.Bson/Serialization/BsonMemberMap.cs b/src/MongoDB.Bson/Serialization/BsonMemberMap.cs
index 734622d6f4e..0aab89027e6 100644
--- a/src/MongoDB.Bson/Serialization/BsonMemberMap.cs
+++ b/src/MongoDB.Bson/Serialization/BsonMemberMap.cs
@@ -264,6 +264,32 @@ public void Freeze()
_frozen = true;
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ GetType().Equals(obj.GetType()) &&
+ obj is BsonMemberMap other &&
+ _frozen.Equals(true) && other._frozen.Equals(true) && // BsonMemberMaps should only be equal if they are frozen
+ object.Equals(_defaultValue, other._defaultValue) &&
+ object.Equals(_defaultValueCreator, other._defaultValueCreator) &&
+ _defaultValueSpecified.Equals(other._defaultValueSpecified) &&
+ object.Equals(_elementName, other._elementName) &&
+ object.Equals(_idGenerator, other._idGenerator) &&
+ _ignoreIfDefault.Equals(other._ignoreIfDefault) &&
+ _ignoreIfNull.Equals(other._ignoreIfNull) &&
+ _isRequired.Equals(other._isRequired) &&
+ object.Equals(_memberInfo, other._memberInfo) &&
+ _order.Equals(other._order) &&
+ object.Equals(_serializer, other._serializer) &&
+ object.Equals(_shouldSerializeMethod, other._shouldSerializeMethod);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Gets the serializer.
///
diff --git a/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs b/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs
index 6f4e7952c10..c3a79af5d02 100644
--- a/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs
+++ b/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs
@@ -127,6 +127,23 @@ public object DeserializeValue(BsonValue value)
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ GetType().Equals(obj.GetType()) &&
+ obj is BsonSerializationInfo other &&
+ object.Equals(_elementName, other._elementName) &&
+ object.Equals(_elementPath, other._elementPath) &&
+ object.Equals(_nominalType, other._nominalType) &&
+ object.Equals(_serializer, other._serializer);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Merges the new BsonSerializationInfo by taking its properties and concatenating its ElementName.
///
diff --git a/src/MongoDB.Bson/Serialization/Conventions/ObjectDiscriminatorConvention.cs b/src/MongoDB.Bson/Serialization/Conventions/ObjectDiscriminatorConvention.cs
index 0742db7b3bb..9a0a7683368 100644
--- a/src/MongoDB.Bson/Serialization/Conventions/ObjectDiscriminatorConvention.cs
+++ b/src/MongoDB.Bson/Serialization/Conventions/ObjectDiscriminatorConvention.cs
@@ -69,6 +69,17 @@ public string ElementName
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ GetType().Equals(obj.GetType()) &&
+ obj is ObjectDiscriminatorConvention other &&
+ object.Equals(_elementName, other._elementName);
+ }
+
///
/// Gets the actual type of an object by reading the discriminator from a BsonReader.
///
@@ -143,5 +154,8 @@ public BsonValue GetDiscriminator(Type nominalType, Type actualType)
{
return TypeNameDiscriminator.GetDiscriminator(actualType);
}
+
+ ///
+ public override int GetHashCode() => 0;
}
}
diff --git a/src/MongoDB.Bson/Serialization/Conventions/StandardDiscriminatorConvention.cs b/src/MongoDB.Bson/Serialization/Conventions/StandardDiscriminatorConvention.cs
index f61ded8ac81..ca4d2cbc117 100644
--- a/src/MongoDB.Bson/Serialization/Conventions/StandardDiscriminatorConvention.cs
+++ b/src/MongoDB.Bson/Serialization/Conventions/StandardDiscriminatorConvention.cs
@@ -77,6 +77,17 @@ public string ElementName
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ GetType().Equals(obj.GetType()) &&
+ obj is StandardDiscriminatorConvention other &&
+ object.Equals(_elementName, other._elementName);
+ }
+
///
/// Gets the actual type of an object by reading the discriminator from a BsonReader.
///
@@ -123,5 +134,8 @@ public Type GetActualType(IBsonReader bsonReader, Type nominalType)
/// The actual type.
/// The discriminator value.
public abstract BsonValue GetDiscriminator(Type nominalType, Type actualType);
+
+ ///
+ public override int GetHashCode() => 0;
}
}
diff --git a/src/MongoDB.Bson/Serialization/Options/RepresentationConverter.cs b/src/MongoDB.Bson/Serialization/Options/RepresentationConverter.cs
index 801dc2b604e..93c4a5cc77f 100644
--- a/src/MongoDB.Bson/Serialization/Options/RepresentationConverter.cs
+++ b/src/MongoDB.Bson/Serialization/Options/RepresentationConverter.cs
@@ -14,7 +14,6 @@
*/
using System;
-using MongoDB.Bson.Serialization.Attributes;
namespace MongoDB.Bson.Serialization.Options
{
@@ -57,6 +56,21 @@ public bool AllowTruncation
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ GetType().Equals(obj.GetType()) &&
+ obj is RepresentationConverter other &&
+ _allowOverflow.Equals(other._allowOverflow) &&
+ _allowTruncation.Equals(other._allowTruncation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Converts a Decimal128 to a Decimal.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BitArraySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BitArraySerializer.cs
index eed92f68d26..779d169f3dc 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BitArraySerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BitArraySerializer.cs
@@ -34,7 +34,6 @@ private static class Flags
// private fields
private readonly SerializerHelper _helper;
- private readonly Int32Serializer _int32Serializer = new Int32Serializer();
private readonly BsonType _representation;
// constructors
@@ -85,6 +84,21 @@ public BsonType Representation
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is BitArraySerializer other &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
+ // protected methods
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
///
/// Deserializes a value.
@@ -110,7 +124,7 @@ protected override BitArray DeserializeValue(BsonDeserializationContext context,
{
switch (flag)
{
- case Flags.Length: length = _int32Serializer.Deserialize(context); break;
+ case Flags.Length: length = Int32Serializer.Instance.Deserialize(context); break;
case Flags.Bytes: bytes = bsonReader.ReadBytes(); break;
}
});
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BooleanSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BooleanSerializer.cs
index e476061bc85..340027eba6b 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BooleanSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BooleanSerializer.cs
@@ -121,6 +121,20 @@ public override bool Deserialize(BsonDeserializationContext context, BsonDeseria
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is BooleanSerializer other &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonArraySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonArraySerializer.cs
index a1ae0ffe900..d667894ce62 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonArraySerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonArraySerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonBinaryDataSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonBinaryDataSerializer.cs
index 341f388df73..2dbef9d0946 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonBinaryDataSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonBinaryDataSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonBooleanSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonBooleanSerializer.cs
index a3747f6ee2a..65d2cad5cc0 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonBooleanSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonBooleanSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs
index bc1ad98ab47..1a536f29dec 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs
@@ -295,6 +295,20 @@ public TClass DeserializeClass(BsonDeserializationContext context)
return CreateInstanceUsingCreator(values);
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is BsonClassMapSerializer other &&
+ object.Equals(_classMap, other._classMap);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Gets the document Id.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonDateTimeSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonDateTimeSerializer.cs
index f6faa268d7e..ffb13c7f124 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonDateTimeSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonDateTimeSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentBackedClassSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentBackedClassSerializer.cs
index e8816611c89..f3df24f3559 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentBackedClassSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentBackedClassSerializer.cs
@@ -16,6 +16,7 @@
using System;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Serializers;
+using MongoDB.Shared;
namespace MongoDB.Bson.Serialization
{
@@ -39,6 +40,20 @@ protected BsonDocumentBackedClassSerializer()
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is BsonDocumentBackedClassSerializer other &&
+ DictionaryComparer.Equals(_memberSerializationInfo, other._memberSerializationInfo);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Tries to get the serialization info for a member.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentSerializer.cs
index 57bd01ac8a8..e053c26fe10 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonDocumentSerializer.cs
@@ -14,8 +14,6 @@
*/
using System;
-using System.Collections.Generic;
-using System.Linq;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization.IdGenerators;
@@ -47,7 +45,7 @@ public static BsonDocumentSerializer Instance
get { return __instance; }
}
- // public methods
+ // protected methods
///
/// Deserializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonDoubleSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonDoubleSerializer.cs
index 4ad357c7201..79acf5d2572 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonDoubleSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonDoubleSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonInt32Serializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonInt32Serializer.cs
index fe44d9b5ce7..38d1c300a91 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonInt32Serializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonInt32Serializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonInt64Serializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonInt64Serializer.cs
index 60c9311ea22..c16cc4ed82c 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonInt64Serializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonInt64Serializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptSerializer.cs
index b4fb4754b1f..8a66794a88b 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptWithScopeSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptWithScopeSerializer.cs
index ed9aacda925..229e862e6d9 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptWithScopeSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonJavaScriptWithScopeSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonMaxKeySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonMaxKeySerializer.cs
index cb2fb896f24..7da69f060a4 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonMaxKeySerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonMaxKeySerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonMinKeySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonMinKeySerializer.cs
index 0603b75c9b9..8c9452d1f79 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonMinKeySerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonMinKeySerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonNullSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonNullSerializer.cs
index 9c228e52ef9..a3e487b9123 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonNullSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonNullSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonObjectIdSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonObjectIdSerializer.cs
index a2de78411aa..ea64294d12b 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonObjectIdSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonObjectIdSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonRegularExpressionSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonRegularExpressionSerializer.cs
index e5f1d6bcecb..421f1c658bd 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonRegularExpressionSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonRegularExpressionSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonStringSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonStringSerializer.cs
index fd5dc3e5f9a..40c310436f9 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonStringSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonStringSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonSymbolSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonSymbolSerializer.cs
index e0966dd44e0..26da0e4ec12 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonSymbolSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonSymbolSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonTimestampSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonTimestampSerializer.cs
index d4d68c90b24..5caf461bd62 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonTimestampSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonTimestampSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonUndefinedSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonUndefinedSerializer.cs
index f3c7e5e3ea1..375162ed2c9 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonUndefinedSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonUndefinedSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonValueCSharpNullSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonValueCSharpNullSerializer.cs
index f639fb2c1c7..46a0dfb4d55 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonValueCSharpNullSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonValueCSharpNullSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-using System.Collections.Generic;
using MongoDB.Bson.IO;
namespace MongoDB.Bson.Serialization.Serializers
@@ -65,6 +64,20 @@ public override TBsonValue Deserialize(BsonDeserializationContext context, BsonD
return _wrappedSerializer.Deserialize(context);
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is BsonValueCSharpNullSerializer other &&
+ object.Equals(_wrappedSerializer, other._wrappedSerializer);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializer.cs
index f1384a7ad56..7cc652ec5bf 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializer.cs
@@ -13,9 +13,6 @@
* limitations under the License.
*/
-
-using System.Collections.Generic;
-using System.Linq;
namespace MongoDB.Bson.Serialization.Serializers
{
///
@@ -44,7 +41,7 @@ public static BsonValueSerializer Instance
get { return __instance; }
}
- // public methods
+ // protected methods
///
/// Deserializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializerBase.cs b/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializerBase.cs
index d106ab7c0e9..e3a5776870c 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializerBase.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/BsonValueSerializerBase.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-
namespace MongoDB.Bson.Serialization.Serializers
{
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/ByteArraySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ByteArraySerializer.cs
index ce17a67ab89..ff3c051192c 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/ByteArraySerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/ByteArraySerializer.cs
@@ -78,6 +78,21 @@ public BsonType Representation
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is ByteArraySerializer other &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
+ // protected methods
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
///
/// Deserializes a value.
diff --git a/src/MongoDB.Bson/Serialization/Serializers/ByteSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ByteSerializer.cs
index aba46107f76..1abd856d086 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/ByteSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/ByteSerializer.cs
@@ -15,10 +15,6 @@
using System;
using System.Globalization;
-using System.IO;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization.Attributes;
-using MongoDB.Bson.Serialization.Options;
namespace MongoDB.Bson.Serialization.Serializers
{
@@ -132,6 +128,20 @@ public override byte Deserialize(BsonDeserializationContext context, BsonDeseria
return value;
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is ByteSerializer other &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/CharSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/CharSerializer.cs
index fef5ad10f8c..796fbd0cafa 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/CharSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/CharSerializer.cs
@@ -14,10 +14,6 @@
*/
using System;
-using System.IO;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization.Attributes;
-using MongoDB.Bson.Serialization.Options;
namespace MongoDB.Bson.Serialization.Serializers
{
@@ -99,6 +95,20 @@ public override char Deserialize(BsonDeserializationContext context, BsonDeseria
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is CharSerializer other &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/CultureInfoSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/CultureInfoSerializer.cs
index cdc853e1c41..e02ab205706 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/CultureInfoSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/CultureInfoSerializer.cs
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-using System;
using System.Globalization;
using MongoDB.Bson.IO;
@@ -32,7 +31,6 @@ private static class Flags
}
// private fields
- private readonly BooleanSerializer _booleanSerializer = new BooleanSerializer();
private readonly SerializerHelper _helper;
// constructors
@@ -48,7 +46,7 @@ public CultureInfoSerializer()
);
}
- // public methods
+ // protected methods
///
/// Deserializes a value.
///
@@ -70,7 +68,7 @@ protected override CultureInfo DeserializeValue(BsonDeserializationContext conte
switch (flag)
{
case Flags.Name: name = bsonReader.ReadString(); break;
- case Flags.UseUserOverride: useUserOverride = _booleanSerializer.Deserialize(context); break;
+ case Flags.UseUserOverride: useUserOverride = BooleanSerializer.Instance.Deserialize(context); break;
}
});
return new CultureInfo(name, useUserOverride);
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DateTimeOffsetSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DateTimeOffsetSerializer.cs
index 48ecf234a86..0aa1052c7f2 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DateTimeOffsetSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DateTimeOffsetSerializer.cs
@@ -33,8 +33,6 @@ private static class Flags
// private fields
private readonly SerializerHelper _helper;
- private readonly Int32Serializer _int32Serializer = new Int32Serializer();
- private readonly Int64Serializer _int64Serializer = new Int64Serializer();
private readonly BsonType _representation;
// constructors
@@ -105,8 +103,8 @@ public override DateTimeOffset Deserialize(BsonDeserializationContext context, B
{
case BsonType.Array:
bsonReader.ReadStartArray();
- ticks = _int64Serializer.Deserialize(context);
- offset = TimeSpan.FromMinutes(_int32Serializer.Deserialize(context));
+ ticks = Int64Serializer.Instance.Deserialize(context);
+ offset = TimeSpan.FromMinutes(Int32Serializer.Instance.Deserialize(context));
bsonReader.ReadEndArray();
return new DateTimeOffset(ticks, offset);
@@ -122,8 +120,8 @@ public override DateTimeOffset Deserialize(BsonDeserializationContext context, B
switch (flag)
{
case Flags.DateTime: bsonReader.SkipValue(); break; // ignore value
- case Flags.Ticks: ticks = _int64Serializer.Deserialize(context); break;
- case Flags.Offset: offset = TimeSpan.FromMinutes(_int32Serializer.Deserialize(context)); break;
+ case Flags.Ticks: ticks = Int64Serializer.Instance.Deserialize(context); break;
+ case Flags.Offset: offset = TimeSpan.FromMinutes(Int32Serializer.Instance.Deserialize(context)); break;
}
});
return new DateTimeOffset(ticks, offset);
@@ -136,6 +134,20 @@ public override DateTimeOffset Deserialize(BsonDeserializationContext context, B
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DateTimeOffsetSerializer other &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DateTimeSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DateTimeSerializer.cs
index 3621681c587..b103be5e48c 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DateTimeSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DateTimeSerializer.cs
@@ -14,11 +14,7 @@
*/
using System;
-using System.Globalization;
-using System.IO;
using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization.Attributes;
-using MongoDB.Bson.Serialization.Options;
namespace MongoDB.Bson.Serialization.Serializers
{
@@ -53,7 +49,6 @@ private static class Flags
// private fields
private readonly bool _dateOnly;
private readonly SerializerHelper _helper;
- private readonly Int64Serializer _int64Serializer = new Int64Serializer();
private readonly DateTimeKind _kind;
private readonly BsonType _representation;
@@ -219,7 +214,7 @@ public override DateTime Deserialize(BsonDeserializationContext context, BsonDes
switch (flag)
{
case Flags.DateTime: bsonReader.SkipValue(); break; // ignore value (use Ticks instead)
- case Flags.Ticks: value = new DateTime(_int64Serializer.Deserialize(context), DateTimeKind.Utc); break;
+ case Flags.Ticks: value = new DateTime(Int64Serializer.Instance.Deserialize(context), DateTimeKind.Utc); break;
}
});
break;
@@ -268,6 +263,22 @@ public override DateTime Deserialize(BsonDeserializationContext context, BsonDes
return value;
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DateTimeSerializer other &&
+ _dateOnly.Equals(other._dateOnly) &&
+ _kind.Equals(other._kind) &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/Decimal128Serializer.cs b/src/MongoDB.Bson/Serialization/Serializers/Decimal128Serializer.cs
index 497e7a06a62..e8e232f799e 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/Decimal128Serializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/Decimal128Serializer.cs
@@ -137,6 +137,21 @@ public override Decimal128 Deserialize(BsonDeserializationContext context, BsonD
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is Decimal128Serializer other &&
+ object.Equals(_converter, other._converter) &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DecimalSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DecimalSerializer.cs
index 75508477139..a6b715cf596 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DecimalSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DecimalSerializer.cs
@@ -147,6 +147,21 @@ public override decimal Deserialize(BsonDeserializationContext context, BsonDese
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DecimalSerializer other &&
+ object.Equals(_converter, other._converter) &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DictionaryInterfaceImplementerSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DictionaryInterfaceImplementerSerializer.cs
index 385e8ba007d..5d07b4e5bad 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DictionaryInterfaceImplementerSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DictionaryInterfaceImplementerSerializer.cs
@@ -16,7 +16,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using MongoDB.Bson.Serialization.Options;
namespace MongoDB.Bson.Serialization.Serializers
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DictionarySerializerBase.cs b/src/MongoDB.Bson/Serialization/Serializers/DictionarySerializerBase.cs
index 9b04916444a..3db1d87e95a 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DictionarySerializerBase.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DictionarySerializerBase.cs
@@ -116,6 +116,22 @@ public IBsonSerializer ValueSerializer
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DictionarySerializerBase other &&
+ _dictionaryRepresentation.Equals(other._dictionaryRepresentation) &&
+ object.Equals(_keySerializer, other._keySerializer) &&
+ object.Equals(_valueSerializer, other._valueSerializer);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
public bool TryGetMemberSerializationInfo(string memberName, out BsonSerializationInfo serializationInfo)
{
@@ -464,6 +480,22 @@ public IBsonSerializer ValueSerializer
}
// public methods
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DictionarySerializerBase other &&
+ _dictionaryRepresentation.Equals(other._dictionaryRepresentation) &&
+ object.Equals(_lazyKeySerializer.Value, other._lazyKeySerializer.Value) &&
+ object.Equals(_lazyValueSerializer.Value, other._lazyValueSerializer.Value);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
public bool TryGetItemSerializationInfo(out BsonSerializationInfo serializationInfo)
{
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs
index 91ca46ef2d0..e02e4297e2e 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs
@@ -151,6 +151,21 @@ public override TInterface Deserialize(BsonDeserializationContext context, BsonD
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DiscriminatedInterfaceSerializer other &&
+ object.Equals(_discriminatorConvention, other._discriminatorConvention) &&
+ object.Equals(_interfaceSerializer, other._interfaceSerializer);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedWrapperSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedWrapperSerializer.cs
index a6fd04d58ce..d3d45d28e89 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedWrapperSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedWrapperSerializer.cs
@@ -13,8 +13,6 @@
* limitations under the License.
*/
-using System;
-using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization.Conventions;
namespace MongoDB.Bson.Serialization.Serializers
@@ -96,6 +94,21 @@ public override TValue Deserialize(BsonDeserializationContext context, BsonDeser
return value;
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DiscriminatedWrapperSerializer other &&
+ object.Equals(_discriminatorConvention, other._discriminatorConvention) &&
+ object.Equals(_wrappedSerializer, other._wrappedSerializer);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Determines whether the reader is positioned at a discriminated wrapper.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DoubleSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DoubleSerializer.cs
index b078c8ab45d..8004cea5b46 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DoubleSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DoubleSerializer.cs
@@ -137,6 +137,21 @@ public override double Deserialize(BsonDeserializationContext context, BsonDeser
}
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DoubleSerializer other &&
+ object.Equals(_converter, other._converter) &&
+ _representation.Equals(other._representation);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
/// Serializes a value.
///
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DowncastingSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DowncastingSerializer.cs
index acfa77ed7d7..a1f1ff0258a 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DowncastingSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DowncastingSerializer.cs
@@ -99,6 +99,20 @@ public override TBase Deserialize(BsonDeserializationContext context, BsonDeseri
return _derivedSerializer.Deserialize(context);
}
+ ///
+ public override bool Equals(object obj)
+ {
+ if (object.ReferenceEquals(obj, null)) { return false; }
+ if (object.ReferenceEquals(this, obj)) { return true; }
+ return
+ base.Equals(obj) &&
+ obj is DowncastingSerializer other &&
+ object.Equals(_derivedSerializer, other._derivedSerializer);
+ }
+
+ ///
+ public override int GetHashCode() => 0;
+
///
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, TBase value)
{
diff --git a/src/MongoDB.Bson/Serialization/Serializers/DynamicDocumentBaseSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DynamicDocumentBaseSerializer.cs
index 0c1cf0bf4e0..d020fd3895d 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/DynamicDocumentBaseSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/DynamicDocumentBaseSerializer.cs
@@ -27,7 +27,7 @@ namespace MongoDB.Bson.Serialization.Serializers
public abstract class DynamicDocumentBaseSerializer : SerializerBase where T : class, IDynamicMetaObjectProvider
{
// private static fields
- private static readonly IBsonSerializer