Skip to content

Commit b5caef6

Browse files
Daniel Hegenerdnickless
authored andcommitted
Cached the "_isValueType" information that used to be retrieved through reflection for every Deserialize call
1 parent f1c3b1b commit b5caef6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private static void CheckForISupportInitializeInterface(out MethodInfo beginInit
5353

5454
// private fields
5555
private BsonClassMap _classMap;
56+
private bool _isValueType;
5657
#if NETSTANDARD1_5
5758
private readonly MethodInfo _beginInitMethodInfo;
5859
private readonly MethodInfo _endInitMethodInfo;
@@ -80,6 +81,7 @@ public BsonClassMapSerializer(BsonClassMap classMap)
8081
}
8182

8283
_classMap = classMap;
84+
_isValueType = _classMap.ClassType.GetTypeInfo().IsValueType;
8385
#if NETSTANDARD1_5
8486
CheckForISupportInitializeInterface(out _beginInitMethodInfo, out _endInitMethodInfo);
8587
#endif
@@ -108,7 +110,7 @@ public override TClass Deserialize(BsonDeserializationContext context, BsonDeser
108110
{
109111
var bsonReader = context.Reader;
110112

111-
if (_classMap.ClassType.GetTypeInfo().IsValueType)
113+
if (_isValueType)
112114
{
113115
var message = string.Format("Value class {0} cannot be deserialized.", _classMap.ClassType.FullName);
114116
throw new BsonSerializationException(message);

0 commit comments

Comments
 (0)