MongoDB.Bson.Serialization.Serializers.BsonInt32Serializer.Deserialize C# (CSharp) Method

Deserialize() public method

Deserializes an object from a BsonReader.
public Deserialize ( MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options ) : object
bsonReader MongoDB.Bson.IO.BsonReader The BsonReader.
nominalType System.Type The nominal type of the object.
actualType System.Type The actual type of the object.
options IBsonSerializationOptions The serialization options.
return object
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BsonInt32));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Int32:
                    return new BsonInt32(bsonReader.ReadInt32());
                default:
                    var message = string.Format("Cannot deserialize BsonInt32 from BsonType {0}.", bsonType);
                    throw new Exception(message);
            }
        }