/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary deserializer.</param> /// <param name="DataType">Optional datatype. If not provided, will be read from the binary source.</param> /// <param name="Embedded">If the object is embedded into another.</param> /// <returns>Deserialized object.</returns> public override object Deserialize(IBsonReader Reader, BsonType?DataType, bool Embedded) { if (!DataType.HasValue) { DataType = Reader.ReadBsonType(); } switch (DataType.Value) { case BsonType.Decimal128: return((char?)Reader.ReadDecimal128()); case BsonType.Double: return((char?)Reader.ReadDouble()); case BsonType.Int32: return((char?)Reader.ReadInt32()); case BsonType.Int64: return((char?)Reader.ReadInt64()); case BsonType.MinKey: Reader.ReadMinKey(); return((char?)char.MinValue); case BsonType.MaxKey: Reader.ReadMaxKey(); return((char?)char.MaxValue); case BsonType.Null: Reader.ReadNull(); return(null); case BsonType.String: string s = Reader.ReadString(); return((char?)(string.IsNullOrEmpty(s) ? (char?)0 : s[0])); default: throw new Exception("Expected a nullable char value."); } }
/// <summary> /// Reads a string value. /// </summary> /// <param name="Reader">Binary reader.</param> /// <param name="FieldDataType">Field data type.</param> /// <returns>String value.</returns> /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception> public static string ReadString(IBsonReader Reader, BsonType FieldDataType) { switch (FieldDataType) { case BsonType.Boolean: return(Reader.ReadBoolean().ToString()); case BsonType.DateTime: return(ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime()).ToString()); case BsonType.Decimal128: return(Reader.ReadDecimal128().ToString()); case BsonType.Double: return(Reader.ReadDouble().ToString()); case BsonType.Int32: return(Reader.ReadInt32().ToString()); case BsonType.Int64: return(Reader.ReadInt64().ToString()); case BsonType.JavaScript: return(Reader.ReadJavaScript()); case BsonType.JavaScriptWithScope: return(Reader.ReadJavaScriptWithScope()); case BsonType.Null: Reader.ReadNull(); return(null); case BsonType.ObjectId: return(Reader.ReadObjectId().ToString()); case BsonType.String: return(Reader.ReadString()); case BsonType.Symbol: return(Reader.ReadSymbol()); default: throw new ArgumentException("Expected a char value, but was a " + FieldDataType.ToString() + ".", nameof(FieldDataType)); } }
/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary deserializer.</param> /// <param name="DataType">Optional datatype. If not provided, will be read from the binary source.</param> /// <param name="Embedded">If the object is embedded into another.</param> /// <returns>Deserialized object.</returns> public override object Deserialize(IBsonReader Reader, BsonType?DataType, bool Embedded) { if (!DataType.HasValue) { DataType = Reader.ReadBsonType(); } switch (DataType.Value) { case BsonType.Boolean: return(Reader.ReadBoolean()); case BsonType.Decimal128: return(Reader.ReadDecimal128() != 0); case BsonType.Double: return(Reader.ReadDouble() != 0); case BsonType.Int32: return(Reader.ReadInt32() != 0); case BsonType.Int64: return(Reader.ReadInt64() != 0); case BsonType.MinKey: Reader.ReadMinKey(); return(false); case BsonType.MaxKey: Reader.ReadMaxKey(); return(true); case BsonType.Null: Reader.ReadNull(); return(null); default: throw new Exception("Expected a boolean value."); } }
/// <summary> /// Reads a char value. /// </summary> /// <param name="Reader">Binary reader.</param> /// <param name="FieldDataType">Field data type.</param> /// <returns>Char value.</returns> /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception> public static char ReadChar(IBsonReader Reader, BsonType FieldDataType) { switch (FieldDataType) { case BsonType.Decimal128: return((char)Reader.ReadDecimal128()); case BsonType.Double: return((char)Reader.ReadDouble()); case BsonType.Int32: return((char)Reader.ReadInt32()); case BsonType.Int64: return((char)Reader.ReadInt64()); case BsonType.MinKey: Reader.ReadMinKey(); return(char.MinValue); case BsonType.MaxKey: Reader.ReadMaxKey(); return(char.MaxValue); case BsonType.String: string s = Reader.ReadString(); return(string.IsNullOrEmpty(s) ? (char)0 : s[0]); default: throw new ArgumentException("Expected a char value, but was a " + FieldDataType.ToString() + ".", nameof(FieldDataType)); } }
/// <summary> /// Reads a single value. /// </summary> /// <param name="Reader">Binary reader.</param> /// <param name="FieldDataType">Field data type.</param> /// <returns>Single value.</returns> /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception> public static float ReadSingle(IBsonReader Reader, BsonType FieldDataType) { switch (FieldDataType) { case BsonType.Boolean: return(Reader.ReadBoolean() ? (float)1 : (float)0); case BsonType.Decimal128: return((float)Reader.ReadDecimal128()); case BsonType.Double: return((float)Reader.ReadDouble()); case BsonType.Int32: return((float)Reader.ReadInt32()); case BsonType.Int64: return((float)Reader.ReadInt64()); case BsonType.String: return(float.Parse(Reader.ReadString())); case BsonType.MinKey: Reader.ReadMinKey(); return(float.MinValue); case BsonType.MaxKey: Reader.ReadMaxKey(); return(float.MaxValue); default: throw new ArgumentException("Expected a single value, but was a " + FieldDataType.ToString() + ".", nameof(FieldDataType)); } }
/// <summary> /// Reads a 64-bit unsigned integer value. /// </summary> /// <param name="Reader">Binary reader.</param> /// <param name="FieldDataType">Field data type.</param> /// <returns>64-bit unsigned integer value.</returns> /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception> public static ulong ReadUInt64(IBsonReader Reader, BsonType FieldDataType) { switch (FieldDataType) { case BsonType.Boolean: return(Reader.ReadBoolean() ? (ulong)1 : (ulong)0); case BsonType.Decimal128: return((ulong)Reader.ReadDecimal128()); case BsonType.Double: return((ulong)Reader.ReadDouble()); case BsonType.Int32: return((ulong)Reader.ReadInt32()); case BsonType.Int64: return((ulong)Reader.ReadInt64()); case BsonType.String: return(ulong.Parse(Reader.ReadString())); case BsonType.MinKey: Reader.ReadMinKey(); return(ulong.MinValue); case BsonType.MaxKey: Reader.ReadMaxKey(); return(ulong.MaxValue); default: throw new ArgumentException("Expected a 64-bit unsigned integer value, but was a " + FieldDataType.ToString() + ".", nameof(FieldDataType)); } }
/***************************************************/ public override object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { IBsonReader reader = context.Reader; BsonType currentBsonType = reader.GetCurrentBsonType(); switch (currentBsonType) { case BsonType.Array: if (context.DynamicArraySerializer != null) { return(context.DynamicArraySerializer.Deserialize(context)); } break; case BsonType.Binary: { BsonBinaryData bsonBinaryData = reader.ReadBinaryData(); BsonBinarySubType subType = bsonBinaryData.SubType; if (subType == BsonBinarySubType.UuidStandard || subType == BsonBinarySubType.UuidLegacy) { return(bsonBinaryData.ToGuid()); } break; } case BsonType.Boolean: return(reader.ReadBoolean()); case BsonType.DateTime: return(new BsonDateTime(reader.ReadDateTime()).ToUniversalTime()); case BsonType.Decimal128: return(reader.ReadDecimal128()); case BsonType.Document: return(DeserializeDiscriminatedValue(context, args)); case BsonType.Double: return(reader.ReadDouble()); case BsonType.Int32: return(reader.ReadInt32()); case BsonType.Int64: return(reader.ReadInt64()); case BsonType.Null: reader.ReadNull(); return(null); case BsonType.ObjectId: return(reader.ReadObjectId()); case BsonType.String: return(reader.ReadString()); } Engine.Reflection.Compute.RecordError($"ObjectSerializer does not support BSON type '{currentBsonType}'."); return(null); }
/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary deserializer.</param> /// <param name="DataType">Optional datatype. If not provided, will be read from the binary source.</param> /// <param name="Embedded">If the object is embedded into another.</param> /// <returns>Deserialized object.</returns> public override object Deserialize(IBsonReader Reader, BsonType?DataType, bool Embedded) { if (!DataType.HasValue) { DataType = Reader.ReadBsonType(); } switch (DataType.Value) { case BsonType.Boolean: return(Enum.ToObject(this.enumType, Reader.ReadBoolean() ? 1 : 0)); case BsonType.Decimal128: return(Enum.ToObject(this.enumType, (int)Reader.ReadDecimal128())); case BsonType.Double: return(Enum.ToObject(this.enumType, Reader.ReadDouble())); case BsonType.Int32: return(Enum.ToObject(this.enumType, Reader.ReadInt32())); case BsonType.Int64: return(Enum.ToObject(this.enumType, Reader.ReadInt64())); case BsonType.String: return(Enum.Parse(this.enumType, Reader.ReadString())); case BsonType.Null: Reader.ReadNull(); return(null); default: throw new Exception("Expected an enum value."); } }
/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary deserializer.</param> /// <param name="DataType">Optional datatype. If not provided, will be read from the binary source.</param> /// <param name="Embedded">If the object is embedded into another.</param> /// <returns>Deserialized object.</returns> public override object Deserialize(IBsonReader Reader, BsonType?DataType, bool Embedded) { if (!DataType.HasValue) { DataType = Reader.ReadBsonType(); } switch (DataType.Value) { case BsonType.Boolean: return(Reader.ReadBoolean() ? (byte?)1 : (byte?)0); case BsonType.Decimal128: return((byte?)Reader.ReadDecimal128()); case BsonType.Double: return((byte?)Reader.ReadDouble()); case BsonType.Int32: return((byte?)Reader.ReadInt32()); case BsonType.Int64: return((byte?)Reader.ReadInt64()); case BsonType.String: return((byte?)byte.Parse(Reader.ReadString())); case BsonType.MinKey: Reader.ReadMinKey(); return((byte?)byte.MinValue); case BsonType.MaxKey: Reader.ReadMaxKey(); return((byte?)byte.MaxValue); case BsonType.Null: Reader.ReadNull(); return(null); default: throw new Exception("Expected a nullable byte value."); } }
public void TestDecimal128ExtendedJson(string json, string expectedValueString, string expectedJson) { using (_bsonReader = new JsonReader(json)) { Assert.Equal(BsonType.Decimal128, _bsonReader.ReadBsonType()); Assert.Equal(Decimal128.Parse(expectedValueString), _bsonReader.ReadDecimal128()); Assert.Equal(BsonReaderState.Initial, _bsonReader.State); } Assert.Equal(expectedJson, BsonSerializer.Deserialize <BsonDecimal128>(json).ToJson()); }
private void DeserializeDataPointAttribute(string attr, IBsonReader reader, ref DataPoint dataPoint) { switch (attr) { case "Value": dataPoint.Value = reader.ReadDecimal128().ToDecimal(); break; case "Unit": if (reader.GetCurrentBsonType() == BsonType.Null) { reader.ReadNull(); dataPoint.Unit = null; } else { dataPoint.Unit = reader.ReadString(); } break; case "Precision": if (reader.GetCurrentBsonType() == BsonType.Null) { reader.ReadNull(); dataPoint.Precision = null; } dataPoint.Precision = reader.ReadDouble(); break; case "Accuracy": if (reader.GetCurrentBsonType() == BsonType.Null) { reader.ReadNull(); dataPoint.Accuracy = null; } dataPoint.Accuracy = reader.ReadDouble(); break; default: throw new DatabaseException("Unknown document attribute", "Measurements"); } }
static object ReadObject(IBsonReader bsonReader) //_120509_173140 sync, test { switch (bsonReader.GetCurrentBsonType()) { case BsonType.Array: return(ReadArray(bsonReader)); // replacement case BsonType.Boolean: return(bsonReader.ReadBoolean()); case BsonType.DateTime: return(BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(bsonReader.ReadDateTime())); case BsonType.Decimal128: return(Decimal128.ToDecimal(bsonReader.ReadDecimal128())); case BsonType.Document: return(ReadCustomObject(bsonReader)); // replacement case BsonType.Double: return(bsonReader.ReadDouble()); case BsonType.Int32: return(bsonReader.ReadInt32()); case BsonType.Int64: return(bsonReader.ReadInt64()); case BsonType.Null: bsonReader.ReadNull(); return(null); case BsonType.ObjectId: return(bsonReader.ReadObjectId()); case BsonType.String: return(bsonReader.ReadString()); case BsonType.Binary: var data = bsonReader.ReadBinaryData(); switch (data.SubType) { case BsonBinarySubType.UuidLegacy: case BsonBinarySubType.UuidStandard: return(data.ToGuid()); default: return(data); } default: return(BsonSerializer.Deserialize <BsonValue>(bsonReader)); } }
/// <summary> /// Reads a boolean value. /// </summary> /// <param name="Reader">Binary reader.</param> /// <param name="FieldDataType">Field data type.</param> /// <returns>Boolean value.</returns> /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception> public static bool ReadBoolean(IBsonReader Reader, BsonType FieldDataType) { switch (FieldDataType) { case BsonType.Boolean: return(Reader.ReadBoolean()); case BsonType.Decimal128: return(Reader.ReadDecimal128() != 0); case BsonType.Double: return(Reader.ReadDouble() != 0); case BsonType.Int32: return(Reader.ReadInt32() != 0); case BsonType.Int64: return(Reader.ReadInt64() != 0); case BsonType.MinKey: Reader.ReadMinKey(); return(false); case BsonType.MaxKey: Reader.ReadMaxKey(); return(true); default: throw new ArgumentException("Expected a boolean value, but was a " + FieldDataType.ToString() + ".", nameof(FieldDataType)); } }
protected virtual decimal readAmount(IBsonReader reader) { BsonMemberMap amountMap = _map.GetMemberMap(m => m.Amount); reader.ReadName(amountMap.ElementName); decimal amount; // support old numeric representations BsonType type = reader.GetCurrentBsonType(); switch (type) { case BsonType.Double: { double amountRead = reader.ReadDouble(); amount = Convert.ToDecimal(amountRead); break; } case BsonType.Decimal128: { Decimal128 amountRead = reader.ReadDecimal128(); amount = Decimal128.ToDecimal(amountRead); break; } case BsonType.String: { string amountRead = reader.ReadString(); amount = decimal.Parse(amountRead, CultureInfo.InvariantCulture); break; } default: var message = $"Cannot convert a {type} to a Decimal."; throw new NotSupportedException(message); } return(amount); }
/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary deserializer.</param> /// <param name="DataType">Optional datatype. If not provided, will be read from the binary source.</param> /// <param name="Embedded">If the object is embedded into another.</param> /// <returns>Deserialized object.</returns> public object Deserialize(IBsonReader Reader, BsonType?DataType, bool Embedded) { if (!DataType.HasValue) { DataType = Reader.ReadBsonType(); } switch (DataType.Value) { case BsonType.Boolean: return(new CaseInsensitiveString(Reader.ReadBoolean().ToString())); case BsonType.DateTime: return(new CaseInsensitiveString(ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime()).ToString())); case BsonType.Decimal128: return(new CaseInsensitiveString(Reader.ReadDecimal128().ToString())); case BsonType.Double: return(new CaseInsensitiveString(Reader.ReadDouble().ToString())); case BsonType.Int32: return(new CaseInsensitiveString(Reader.ReadInt32().ToString())); case BsonType.Int64: return(new CaseInsensitiveString(Reader.ReadInt64().ToString())); case BsonType.JavaScript: return(new CaseInsensitiveString(Reader.ReadJavaScript())); case BsonType.JavaScriptWithScope: return(new CaseInsensitiveString(Reader.ReadJavaScriptWithScope())); case BsonType.Null: Reader.ReadNull(); return(null); case BsonType.ObjectId: return(new CaseInsensitiveString(Reader.ReadObjectId().ToString())); case BsonType.String: return(new CaseInsensitiveString(Reader.ReadString())); case BsonType.Symbol: return(new CaseInsensitiveString(Reader.ReadSymbol())); default: throw new Exception("Expected a case-insensitive string value."); } }
/// <summary> /// Reads a BSON Decimal128 element from the reader. /// </summary> /// <param name="reader">The reader.</param> /// <param name="name">The name of the element.</param> /// <returns>A <see cref="Decimal128"/>.</returns> public static Decimal128 ReadDecimal128(this IBsonReader reader, string name) { VerifyName(reader, name); return(reader.ReadDecimal128()); }
public void TestDecimal128ExtendedJson(string json, string expectedValueString, string expectedJson) { using (_bsonReader = new JsonReader(json)) { Assert.Equal(BsonType.Decimal128, _bsonReader.ReadBsonType()); Assert.Equal(Decimal128.Parse(expectedValueString), _bsonReader.ReadDecimal128()); Assert.Equal(BsonReaderState.Initial, _bsonReader.State); } Assert.Equal(expectedJson, BsonSerializer.Deserialize<BsonDecimal128>(json).ToJson()); }
/// <summary> /// Deserializes an object from a binary source. /// </summary> /// <param name="Reader">Binary deserializer.</param> /// <param name="DataType">Optional datatype. If not provided, will be read from the binary source.</param> /// <param name="Embedded">If the object is embedded into another.</param> /// <returns>Deserialized object.</returns> public override object Deserialize(IBsonReader Reader, BsonType?DataType, bool Embedded) { BsonReaderBookmark Bookmark = Reader.GetBookmark(); BsonType? DataTypeBak = DataType; if (!DataType.HasValue) { DataType = Reader.ReadBsonType(); } switch (DataType.Value) { case BsonType.Document: break; case BsonType.Boolean: return(Reader.ReadBoolean()); case BsonType.Int32: return(Reader.ReadInt32()); case BsonType.Int64: return(Reader.ReadInt64()); case BsonType.Decimal128: return((decimal)Reader.ReadDecimal128()); case BsonType.Double: return(Reader.ReadDouble()); case BsonType.DateTime: return(ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime())); case BsonType.String: case BsonType.Symbol: case BsonType.JavaScript: case BsonType.JavaScriptWithScope: return(Reader.ReadString()); case BsonType.Binary: return(Reader.ReadBytes()); case BsonType.Null: Reader.ReadNull(); return(null); default: throw new Exception("Object or value expected."); } LinkedList <KeyValuePair <string, object> > Properties = new LinkedList <KeyValuePair <string, object> >(); LinkedList <KeyValuePair <string, object> > LowerCase = null; string TypeName = string.Empty; Guid ObjectId = Guid.Empty; string CollectionName = string.Empty; string FieldName; BsonType ValueType; object Value; Reader.ReadStartDocument(); while (Reader.State == BsonReaderState.Type) { ValueType = Reader.ReadBsonType(); if (ValueType == BsonType.EndOfDocument) { break; } FieldName = Reader.ReadName(); switch (ValueType) { case BsonType.Array: Value = GeneratedObjectSerializerBase.ReadArray(null, this.Provider, Reader, ValueType); break; case BsonType.Binary: Value = Reader.ReadBytes(); break; case BsonType.Boolean: Value = Reader.ReadBoolean(); break; case BsonType.DateTime: Value = ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime()); break; case BsonType.Decimal128: Value = (decimal)Reader.ReadDecimal128(); break; case BsonType.Document: Value = this.Deserialize(Reader, ValueType, true); break; case BsonType.Double: Value = Reader.ReadDouble(); break; case BsonType.Int32: Value = Reader.ReadInt32(); break; case BsonType.Int64: Value = Reader.ReadInt64(); break; case BsonType.JavaScript: Value = Reader.ReadJavaScript(); break; case BsonType.JavaScriptWithScope: Value = Reader.ReadJavaScriptWithScope(); break; case BsonType.Null: Value = null; Reader.ReadNull(); break; case BsonType.ObjectId: Value = Reader.ReadObjectId(); break; case BsonType.String: Value = Reader.ReadString(); break; case BsonType.Symbol: Value = Reader.ReadSymbol(); break; default: throw new Exception("Unrecognized data type: " + ValueType.ToString()); } switch (FieldName) { case "_id": if (Value is Guid Guid) { ObjectId = Guid; } else if (Value is string s) { ObjectId = new Guid(s); } else if (Value is byte[] A) { ObjectId = new Guid(A); } else if (Value is ObjectId ObjId) { ObjectId = GeneratedObjectSerializerBase.ObjectIdToGuid(ObjId); } else { throw new Exception("Unrecognized Object ID type: " + Value.GetType().FullName); } break; case "_type": TypeName = Value?.ToString(); if (this.returnTypedObjects && !string.IsNullOrEmpty(TypeName)) { Type DesiredType = Types.GetType(TypeName); if (DesiredType is null) { DesiredType = typeof(GenericObject); } if (DesiredType != typeof(GenericObject)) { IObjectSerializer Serializer2 = this.provider.GetObjectSerializer(DesiredType); Reader.ReturnToBookmark(Bookmark); return(Serializer2.Deserialize(Reader, DataTypeBak, Embedded)); } } break; case "_collection": CollectionName = Value?.ToString(); break; default: if (FieldName.EndsWith("_L")) { string s = FieldName.Substring(0, FieldName.Length - 2); bool Ignore = false; foreach (KeyValuePair <string, object> P in Properties) { if (P.Key == s) { Ignore = true; break; } } if (!Ignore) { if (LowerCase is null) { LowerCase = new LinkedList <KeyValuePair <string, object> >(); } LowerCase.AddLast(new KeyValuePair <string, object>(s, Value)); } } else { Properties.AddLast(new KeyValuePair <string, object>(FieldName, Value)); } break; } } if (!(LowerCase is null)) { foreach (KeyValuePair <string, object> P in LowerCase) { bool Ignore = false; foreach (KeyValuePair <string, object> P2 in Properties) { if (P2.Key == P.Key) { Ignore = true; break; } } if (!Ignore) { Properties.AddLast(new KeyValuePair <string, object>(P.Key + "_L", P.Value)); } } } Reader.ReadEndDocument(); return(new GenericObject(CollectionName, TypeName, ObjectId, Properties)); }
public override bool Read() { if (bsonReader.State == BsonReaderState.Initial || bsonReader.State == BsonReaderState.ScopeDocument || bsonReader.State == BsonReaderState.Type) { bsonReader.ReadBsonType(); } if (bsonReader.State == BsonReaderState.Name) { SetToken(NewtonsoftJsonToken.PropertyName, bsonReader.ReadName().UnescapeBson()); } else if (bsonReader.State == BsonReaderState.Value) { switch (bsonReader.CurrentBsonType) { case BsonType.Document: SetToken(NewtonsoftJsonToken.StartObject); bsonReader.ReadStartDocument(); break; case BsonType.Array: SetToken(NewtonsoftJsonToken.StartArray); bsonReader.ReadStartArray(); break; case BsonType.Undefined: SetToken(NewtonsoftJsonToken.Undefined); bsonReader.ReadUndefined(); break; case BsonType.Null: SetToken(NewtonsoftJsonToken.Null); bsonReader.ReadNull(); break; case BsonType.String: SetToken(NewtonsoftJsonToken.String, bsonReader.ReadString()); break; case BsonType.Binary: SetToken(NewtonsoftJsonToken.Bytes, bsonReader.ReadBinaryData().Bytes); break; case BsonType.Boolean: SetToken(NewtonsoftJsonToken.Boolean, bsonReader.ReadBoolean()); break; case BsonType.DateTime: SetToken(NewtonsoftJsonToken.Date, bsonReader.ReadDateTime()); break; case BsonType.Int32: SetToken(NewtonsoftJsonToken.Integer, bsonReader.ReadInt32()); break; case BsonType.Int64: SetToken(NewtonsoftJsonToken.Integer, bsonReader.ReadInt64()); break; case BsonType.Double: SetToken(NewtonsoftJsonToken.Float, bsonReader.ReadDouble()); break; case BsonType.Decimal128: SetToken(NewtonsoftJsonToken.Float, Decimal128.ToDouble(bsonReader.ReadDecimal128())); break; default: throw new NotSupportedException(); } } else if (bsonReader.State == BsonReaderState.EndOfDocument) { SetToken(NewtonsoftJsonToken.EndObject); bsonReader.ReadEndDocument(); } else if (bsonReader.State == BsonReaderState.EndOfArray) { SetToken(NewtonsoftJsonToken.EndArray); bsonReader.ReadEndArray(); } if (bsonReader.State == BsonReaderState.Initial) { return(true); } return(!bsonReader.IsAtEndOfFile()); }