Details
-
Improvement
-
Resolution: Works as Designed
-
Major - P3
-
None
-
2.7.0
Description
In the source code of c# Driver v2.7,
namespace MongoDB.Bson.Serialization.Serializers |
{
|
public class EnumSerializer<TEnum> : StructSerializerBase<TEnum>, IRepresentationConfigurable<EnumSerializer<TEnum>> where TEnum : struct |
{
|
......
|
public override TEnum Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) |
{
|
var bsonReader = context.Reader; |
|
|
var bsonType = bsonReader.GetCurrentBsonType(); |
switch (bsonType) |
{
|
......
|
case BsonType.String: return (TEnum)Enum.Parse(typeof(TEnum), bsonReader.ReadString()); |
default: |
throw CreateCannotDeserializeFromBsonTypeException(bsonType); |
}
|
}
|
......
|
}
|
}
|
In this method, the code
case BsonType.String: return (TEnum)Enum.Parse(typeof(TEnum), bsonReader.ReadString()); |
will throw an ArgumentException when the ReadString() returns a value that is not defined in the TEnum type.