From 06ff2c4bbfa94a1bdaf3a873f3f3872ee2946062 Mon Sep 17 00:00:00 2001 From: Derek Ludwig Date: Wed, 9 Nov 2011 15:19:13 -0800 Subject: [PATCH] Enabled JsonReader to read an Int64 when the input value is within the range int.MinValue to int.MaxValue. --- Bson/IO/BsonReader.cs | 7 ++++--- Bson/IO/JsonReader.cs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Bson/IO/BsonReader.cs b/Bson/IO/BsonReader.cs index 14f5ad3..46cdc70 100644 --- a/Bson/IO/BsonReader.cs +++ b/Bson/IO/BsonReader.cs @@ -771,7 +771,7 @@ namespace MongoDB.Bson.IO { /// The required BSON type. protected void VerifyBsonType( string methodName, - BsonType requiredBsonType + params BsonType[] requiredBsonTypes ) { if (state == BsonReaderState.Initial || state == BsonReaderState.ScopeDocument || state == BsonReaderState.Type) { ReadBsonType(); @@ -783,8 +783,9 @@ namespace MongoDB.Bson.IO { if (state != BsonReaderState.Value) { ThrowInvalidState(methodName, BsonReaderState.Value); } - if (currentBsonType != requiredBsonType) { - var message = string.Format("{0} can only be called when CurrentBsonType is {1}, not when CurrentBsonType is {2}.", methodName, requiredBsonType, currentBsonType); + if (!requiredBsonTypes.Any(type => type == currentBsonType)) { + var types = string.Join(" or ", requiredBsonTypes.Select(type => type.ToString()).ToArray()); + var message = string.Format("{0} can only be called when CurrentBsonType is {1}, not when CurrentBsonType is {2}.", methodName, types, currentBsonType); throw new InvalidOperationException(message); } } diff --git a/Bson/IO/JsonReader.cs b/Bson/IO/JsonReader.cs index 19273d6..b4c826c 100644 --- a/Bson/IO/JsonReader.cs +++ b/Bson/IO/JsonReader.cs @@ -381,9 +381,9 @@ namespace MongoDB.Bson.IO { /// An Int64. public override long ReadInt64() { if (disposed) { ThrowObjectDisposedException(); } - VerifyBsonType("ReadInt64", BsonType.Int64); + VerifyBsonType("ReadInt64", BsonType.Int64, BsonType.Int32); state = GetNextState(); - return currentValue.AsInt64; + return currentValue.ToInt64(); } /// -- 1.7.4.msysgit.0