Exemplo n.º 1
0
        /// <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 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>
        /// 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.");
            }
        }
Exemplo n.º 4
0
        /// <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.");
            }
        }
        /// <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 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));
            }
        }
        /// <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.DateTime: return((DateTimeOffset?)ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime()));

            case BsonType.String: return((DateTimeOffset?)DateTimeOffset.Parse(Reader.ReadString()));

            case BsonType.Document:
                DateTime TP = DateTime.MinValue;
                TimeSpan TZ = TimeSpan.Zero;

                Reader.ReadStartDocument();

                while (Reader.State == BsonReaderState.Type)
                {
                    BsonType BsonType = Reader.ReadBsonType();
                    if (BsonType == BsonType.EndOfDocument)
                    {
                        break;
                    }

                    string FieldName = Reader.ReadName();
                    switch (FieldName)
                    {
                    case "tp":
                        TP = ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime());
                        break;

                    case "tz":
                        TZ = TimeSpan.Parse(Reader.ReadString());
                        break;
                    }
                }

                Reader.ReadEndDocument();

                return((DateTimeOffset?)new DateTimeOffset(TP, TZ));

            case BsonType.MinKey: Reader.ReadMinKey(); return((DateTimeOffset?)DateTimeOffset.MinValue);

            case BsonType.MaxKey: Reader.ReadMaxKey(); return((DateTimeOffset?)DateTimeOffset.MaxValue);

            case BsonType.Null: Reader.ReadNull(); return(null);

            default: throw new Exception("Expected a nullable DateTimeOffset value.");
            }
        }
Exemplo n.º 8
0
        public void TestMaxKeyKeyword()
        {
            var json = "MaxKey";

            using (_bsonReader = new JsonReader(json))
            {
                Assert.Equal(BsonType.MaxKey, _bsonReader.ReadBsonType());
                _bsonReader.ReadMaxKey();
                Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
            }
            Assert.Equal(json, BsonSerializer.Deserialize <BsonMaxKey>(new StringReader(json)).ToJson());
        }
Exemplo n.º 9
0
        public void TestMaxKeyExtendedJsonWithCapitalK()
        {
            var json = "{ \"$maxKey\" : 1 }";

            using (_bsonReader = new JsonReader(json))
            {
                Assert.Equal(BsonType.MaxKey, _bsonReader.ReadBsonType());
                _bsonReader.ReadMaxKey();
                Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
            }
            var canonicalJson = "MaxKey";

            Assert.Equal(canonicalJson, BsonSerializer.Deserialize <BsonMaxKey>(new StringReader(json)).ToJson());
        }
        /// <summary>
        /// Reads a time span value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>TimeSpan value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static TimeSpan ReadTimeSpan(IBsonReader Reader, BsonType FieldDataType)
        {
            switch (FieldDataType)
            {
            case BsonType.String: return(TimeSpan.Parse(Reader.ReadString()));

            case BsonType.MinKey: Reader.ReadMinKey(); return(TimeSpan.MinValue);

            case BsonType.MaxKey: Reader.ReadMaxKey(); return(TimeSpan.MaxValue);

            default:
                throw new ArgumentException("Expected a time span value, but was a " +
                                            FieldDataType.ToString() + ".", nameof(FieldDataType));
            }
        }
        /// <summary>
        /// Reads a date &amp; time value with offset.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>DateTimeOffset value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static DateTimeOffset ReadDateTimeOffset(IBsonReader Reader, BsonType FieldDataType)
        {
            switch (FieldDataType)
            {
            case BsonType.DateTime: return((DateTimeOffset)ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime()));

            case BsonType.String: return(DateTimeOffset.Parse(Reader.ReadString()));

            case BsonType.Document:
                DateTime TP = DateTime.MinValue;
                TimeSpan TZ = TimeSpan.Zero;

                Reader.ReadStartDocument();

                while (Reader.State == BsonReaderState.Type)
                {
                    BsonType BsonType = Reader.ReadBsonType();
                    if (BsonType == BsonType.EndOfDocument)
                    {
                        break;
                    }

                    string FieldName = Reader.ReadName();
                    switch (FieldName)
                    {
                    case "tp":
                        TP = ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime());
                        break;

                    case "tz":
                        TZ = TimeSpan.Parse(Reader.ReadString());
                        break;
                    }
                }

                Reader.ReadEndDocument();

                return(new DateTimeOffset(TP, TZ));

            case BsonType.MinKey: Reader.ReadMinKey(); return(DateTimeOffset.MinValue);

            case BsonType.MaxKey: Reader.ReadMaxKey(); return(DateTimeOffset.MaxValue);

            default:
                throw new ArgumentException("Expected a date & time value with offset, but was a " +
                                            FieldDataType.ToString() + ".", nameof(FieldDataType));
            }
        }
        /// <summary>
        /// Reads a date &amp; time value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>DateTime value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static DateTime ReadDateTime(IBsonReader Reader, BsonType FieldDataType)
        {
            switch (FieldDataType)
            {
            case BsonType.DateTime: return(ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime()));

            case BsonType.String: return(DateTime.Parse(Reader.ReadString()));

            case BsonType.MinKey: Reader.ReadMinKey(); return(DateTime.MinValue);

            case BsonType.MaxKey: Reader.ReadMaxKey(); return(DateTime.MaxValue);

            default:
                throw new ArgumentException("Expected a date & time value, but was a " +
                                            FieldDataType.ToString() + ".", nameof(FieldDataType));
            }
        }
Exemplo n.º 13
0
        /// <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.String: return(TimeSpan.Parse(Reader.ReadString()));

            case BsonType.MinKey: Reader.ReadMinKey(); return(TimeSpan.MinValue);

            case BsonType.MaxKey: Reader.ReadMaxKey(); return(TimeSpan.MaxValue);

            case BsonType.Null: Reader.ReadNull(); return(null);

            default: throw new Exception("Expected a TimeSpan 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.DateTime: return((DateTime?)ObjectSerializer.UnixEpoch.AddMilliseconds(Reader.ReadDateTime()));

            case BsonType.String: return((DateTime?)DateTime.Parse(Reader.ReadString()));

            case BsonType.MinKey: Reader.ReadMinKey(); return((DateTime?)DateTime.MinValue);

            case BsonType.MaxKey: Reader.ReadMaxKey(); return((DateTime?)DateTime.MaxValue);

            case BsonType.Null: Reader.ReadNull(); return(null);

            default: throw new Exception("Expected a nullable DateTime value.");
            }
        }
        /// <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));
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Reads a BSON MaxKey element from the reader.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="name">The name of the element.</param>
 public static void ReadMaxKey(this IBsonReader reader, string name)
 {
     VerifyName(reader, name);
     reader.ReadMaxKey();
 }
Exemplo n.º 17
0
        // private methods
        private void ReadValue()
        {
            object jsonDotNetValue;

            switch (_wrappedReader.GetCurrentBsonType())
            {
            case BsonType.Array:
                _wrappedReader.ReadStartArray();
                SetCurrentToken(Newtonsoft.Json.JsonToken.StartArray);
                return;

            case BsonType.Binary:
                var bsonBinaryData = _wrappedReader.ReadBinaryData();
                switch (bsonBinaryData.SubType)
                {
                case BsonBinarySubType.UuidLegacy:
                    var guidRepresentation = GuidRepresentation.Unspecified;
                    var bsonReader         = _wrappedReader as BsonReader;
                    if (bsonReader != null)
                    {
                        guidRepresentation = bsonReader.Settings.GuidRepresentation;
                    }
                    jsonDotNetValue = GuidConverter.FromBytes(bsonBinaryData.Bytes, guidRepresentation);
                    break;

                case BsonBinarySubType.UuidStandard:
                    jsonDotNetValue = GuidConverter.FromBytes(bsonBinaryData.Bytes, GuidRepresentation.Standard);
                    break;

                default:
                    jsonDotNetValue = bsonBinaryData.Bytes;
                    break;
                }
                SetCurrentToken(Newtonsoft.Json.JsonToken.Bytes, jsonDotNetValue, bsonBinaryData);
                return;

            case BsonType.Boolean:
                var booleanValue = _wrappedReader.ReadBoolean();
                SetCurrentToken(Newtonsoft.Json.JsonToken.Boolean, booleanValue, (BsonBoolean)booleanValue);
                return;

            case BsonType.DateTime:
                var bsonDateTime = new BsonDateTime(_wrappedReader.ReadDateTime());
                if (bsonDateTime.IsValidDateTime)
                {
                    jsonDotNetValue = bsonDateTime.ToUniversalTime();
                }
                else
                {
                    jsonDotNetValue = bsonDateTime.MillisecondsSinceEpoch;
                }
                SetCurrentToken(Newtonsoft.Json.JsonToken.Date, jsonDotNetValue, bsonDateTime);
                return;

            case BsonType.Document:
                _wrappedReader.ReadStartDocument();
                SetCurrentToken(Newtonsoft.Json.JsonToken.StartObject);
                return;

            case BsonType.Double:
                var bsonDouble = new BsonDouble(_wrappedReader.ReadDouble());
                switch (FloatParseHandling)
                {
                case Newtonsoft.Json.FloatParseHandling.Decimal:
                    jsonDotNetValue = Convert.ToDecimal(bsonDouble);
                    break;

                case Newtonsoft.Json.FloatParseHandling.Double:
                    jsonDotNetValue = bsonDouble.Value;
                    break;

                default:
                    throw new NotSupportedException(string.Format("Unexpected FloatParseHandling value: {0}.", FloatParseHandling));
                }
                SetCurrentToken(Newtonsoft.Json.JsonToken.Float, jsonDotNetValue, bsonDouble);
                return;

            case BsonType.Int32:
                var bsonInt32 = (BsonInt32)_wrappedReader.ReadInt32();
                SetCurrentToken(Newtonsoft.Json.JsonToken.Integer, (long)bsonInt32.Value, bsonInt32);
                return;

            case BsonType.Int64:
                var bsonInt64 = (BsonInt64)_wrappedReader.ReadInt64();
                SetCurrentToken(Newtonsoft.Json.JsonToken.Integer, bsonInt64.Value, bsonInt64);
                return;

            case BsonType.JavaScript:
            {
                var code           = _wrappedReader.ReadJavaScript();
                var bsonJavaScript = new BsonJavaScript(code);
                SetCurrentToken(Newtonsoft.Json.JsonToken.String, code, bsonJavaScript);
            }
                return;

            case BsonType.JavaScriptWithScope:
            {
                var code    = _wrappedReader.ReadJavaScriptWithScope();
                var context = BsonDeserializationContext.CreateRoot(_wrappedReader);
                var scope   = BsonDocumentSerializer.Instance.Deserialize <BsonDocument>(context);
                var bsonJavaScriptWithScope = new BsonJavaScriptWithScope(code, scope);
                SetCurrentToken(Newtonsoft.Json.JsonToken.String, code, bsonJavaScriptWithScope);
            }
                return;

            case BsonType.MaxKey:
                _wrappedReader.ReadMaxKey();
                SetCurrentToken(Newtonsoft.Json.JsonToken.Undefined, null, BsonMaxKey.Value);
                return;

            case BsonType.MinKey:
                _wrappedReader.ReadMinKey();
                SetCurrentToken(Newtonsoft.Json.JsonToken.Undefined, null, BsonMinKey.Value);
                return;

            case BsonType.Null:
                _wrappedReader.ReadNull();
                SetCurrentToken(Newtonsoft.Json.JsonToken.Null, null, BsonNull.Value);
                return;

            case BsonType.ObjectId:
                var bsonObjectId = new BsonObjectId(_wrappedReader.ReadObjectId());
                SetCurrentToken(Newtonsoft.Json.JsonToken.Bytes, bsonObjectId.Value.ToByteArray(), bsonObjectId);
                return;

            case BsonType.RegularExpression:
                var bsonRegularExpression = _wrappedReader.ReadRegularExpression();
                var pattern = bsonRegularExpression.Pattern;
                var options = bsonRegularExpression.Options;
                jsonDotNetValue = "/" + pattern.Replace("/", "\\/") + "/" + options;
                SetCurrentToken(Newtonsoft.Json.JsonToken.String, jsonDotNetValue, bsonRegularExpression);
                return;

            case BsonType.String:
                var stringValue = _wrappedReader.ReadString();
                SetCurrentToken(Newtonsoft.Json.JsonToken.String, stringValue, (BsonString)stringValue);
                return;

            case BsonType.Symbol:
                var bsonSymbol = BsonSymbolTable.Lookup(_wrappedReader.ReadSymbol());
                SetCurrentToken(Newtonsoft.Json.JsonToken.String, bsonSymbol.Name, bsonSymbol);
                return;

            case BsonType.Timestamp:
                var bsonTimestamp = new BsonTimestamp(_wrappedReader.ReadTimestamp());
                SetCurrentToken(Newtonsoft.Json.JsonToken.Integer, bsonTimestamp.Value, bsonTimestamp);
                return;

            case BsonType.Undefined:
                _wrappedReader.ReadUndefined();
                SetCurrentToken(Newtonsoft.Json.JsonToken.Undefined, null, BsonUndefined.Value);
                return;

            default:
                var message = string.Format("Unexpected BsonType: {0}.", _wrappedReader.GetCurrentBsonType());
                throw new Newtonsoft.Json.JsonReaderException(message);
            }
        }
 public void TestMaxKeyKeyword()
 {
     var json = "MaxKey";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.MaxKey, _bsonReader.ReadBsonType());
         _bsonReader.ReadMaxKey();
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonMaxKey>(new StringReader(json)).ToJson());
 }
 public void TestMaxKeyExtendedJsonWithCapitalK()
 {
     var json = "{ \"$maxKey\" : 1 }";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.MaxKey, _bsonReader.ReadBsonType());
         _bsonReader.ReadMaxKey();
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     var canonicalJson = "MaxKey";
     Assert.Equal(canonicalJson, BsonSerializer.Deserialize<BsonMaxKey>(new StringReader(json)).ToJson());
 }