Skip to content

Commit 35545b2

Browse files
author
Daniel Hegener
committed
Cached the "_isValueType" information that used to be retrieved through reflection for every Deserialize call
1 parent 8ea4e7b commit 35545b2

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
@@ -31,6 +31,7 @@ public class BsonClassMapSerializer<TClass> : SerializerBase<TClass>, IBsonIdPro
3131
{
3232
// private fields
3333
private BsonClassMap _classMap;
34+
private bool _isValueType;
3435

3536
// constructors
3637
/// <summary>
@@ -54,6 +55,7 @@ public BsonClassMapSerializer(BsonClassMap classMap)
5455
}
5556

5657
_classMap = classMap;
58+
_isValueType = _classMap.ClassType.GetTypeInfo().IsValueType;
5759
}
5860

5961
// public properties
@@ -79,7 +81,7 @@ public override TClass Deserialize(BsonDeserializationContext context, BsonDeser
7981
{
8082
var bsonReader = context.Reader;
8183

82-
if (_classMap.ClassType.GetTypeInfo().IsValueType)
84+
if (_isValueType)
8385
{
8486
var message = string.Format("Value class {0} cannot be deserialized.", _classMap.ClassType.FullName);
8587
throw new BsonSerializationException(message);

0 commit comments

Comments
 (0)