// private methods
        private void DeserializeExtraElement(BsonReader bsonReader, object obj, string elementName, BsonMemberMap extraElementsMemberMap)
        {
            var extraElements = (BsonDocument)extraElementsMemberMap.Getter(obj);

            if (extraElements == null)
            {
                extraElements = new BsonDocument();
                extraElementsMemberMap.Setter(obj, extraElements);
            }
            var value = BsonValue.ReadFrom(bsonReader);

            extraElements[elementName] = value;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads a BsonArray from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The reader.</param>
        /// <returns>A BsonArray.</returns>
        public static new BsonArray ReadFrom(BsonReader bsonReader)
        {
            var array = new BsonArray();

            bsonReader.ReadStartArray();
            while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
            {
                var value = BsonValue.ReadFrom(bsonReader);
                array.Add(value);
            }
            bsonReader.ReadEndArray();
            return(array);
        }
        private void DeserializeExtraElement(BsonReader bsonReader, object obj, string elementName, BsonMemberMap extraElementsMemberMap)
        {
            BsonDocument bsonDocument = (BsonDocument)extraElementsMemberMap.Getter(obj);

            if (bsonDocument == (BsonDocument)null)
            {
                bsonDocument = new BsonDocument();
                extraElementsMemberMap.Setter(obj, (object)bsonDocument);
            }
            BsonValue bsonValue = BsonValue.ReadFrom(bsonReader);

            bsonDocument[elementName] = bsonValue;
        }
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, // ignored
                                           IBsonSerializationOptions options)
        {
            var bsonType = bsonReader.GetCurrentBsonType();

            if (bsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                return(BsonValue.ReadFrom(bsonReader));
            }
        }
Exemplo n.º 5
0
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(MongoDBRef));

            if (bsonReader.GetCurrentBsonType() == Bson.BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                string    databaseName   = null;
                string    collectionName = null;
                BsonValue id             = null;

                bsonReader.ReadStartDocument();
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    var name = bsonReader.ReadName();
                    switch (name)
                    {
                    case "$ref":
                        collectionName = bsonReader.ReadString();
                        break;

                    case "$id":
                        id = BsonValue.ReadFrom(bsonReader);;
                        break;

                    case "$db":
                        databaseName = bsonReader.ReadString();
                        break;

                    default:
                        var message = string.Format("Element '{0}' is not valid for MongoDBRef.", name);
                        throw new FileFormatException(message);
                    }
                }
                bsonReader.ReadEndDocument();

                return(new MongoDBRef(databaseName, collectionName, id));
            }
        }
Exemplo n.º 6
0
        // internal static methods
        internal static bool ReadFrom(BsonReader bsonReader, out BsonElement element)
        {
            BsonType bsonType;

            if ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
            {
                var name  = bsonReader.ReadName();
                var value = BsonValue.ReadFrom(bsonReader);
                element = new BsonElement(name, value);
                return(true);
            }
            else
            {
                element = null;
                return(false);
            }
        }
Exemplo n.º 7
0
        object IBsonSerializable.Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            IBsonSerializationOptions options
            )
        {
            if (bsonReader.CurrentBsonType == Bson.BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                bsonReader.ReadStartDocument();
                string   message;
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    var name = bsonReader.ReadName();
                    switch (name)
                    {
                    case "$ref":
                        collectionName = bsonReader.ReadString();
                        break;

                    case "$id":
                        id = BsonValue.ReadFrom(bsonReader);;
                        break;

                    case "$db":
                        databaseName = bsonReader.ReadString();
                        break;

                    default:
                        message = string.Format("Invalid element for DBRef: {0}", name);
                        throw new FileFormatException(message);
                    }
                }
                bsonReader.ReadEndDocument();
                return(this);
            }
        }
Exemplo n.º 8
0
        public Type GetActualType(BsonReader bsonReader, System.Type nominalType)
        {
            var currentBsonType = bsonReader.GetCurrentBsonType();

            if (bsonReader.State == BsonReaderState.Value)
            {
                if (currentBsonType == BsonType.Document)
                {
                    var bookmark = bsonReader.GetBookmark();
                    bsonReader.ReadStartDocument();
                    var type = nominalType;
                    if (bsonReader.FindElement(ElementName))
                    {
                        var discriminator = BsonValue.ReadFrom(bsonReader).AsString;
                        try
                        {
                            if (discriminator == "Typed")
                            {
                                type = typeof(TypedSettings <>);

                                bsonReader.ReturnToBookmark(bookmark);
                                bsonReader.ReadStartDocument();
                                bsonReader.FindElement("Name");
                                var stringType = BsonValue.ReadFrom(bsonReader).AsString;
                                type = type.MakeGenericType(Type.GetType(stringType));
                            }
                            else if (discriminator == "Setting")
                            {
                                type = typeof(Setting);
                            }
                        }
                        catch (Exception ex)
                        {
                            type = typeof(Setting);
                        }
                    }
                    bsonReader.ReturnToBookmark(bookmark);
                    return(type);
                }
            }
            return(nominalType);
        }
Exemplo n.º 9
0
        public static BsonValue ToBsonValue(this string valueInJsonFormat)
        {
            if (string.IsNullOrWhiteSpace(valueInJsonFormat))
            {
                return(BsonNull.Value);
            }

            try
            {
                using (var reader = BsonReader.Create(valueInJsonFormat))
                {
                    return(BsonValue.ReadFrom(reader));
                }
            }
            catch (Exception e)
            {
                string text = String.Format(Messages.InvalidJsonValue, valueInJsonFormat ?? "is null");
                throw new ArgumentException(text, "valueInJsonFormat", e);
            }
        }
Exemplo n.º 10
0
 // private methods
 private void DeserializeExtraElement(
     BsonReader bsonReader,
     object obj,
     string elementName,
     BsonMemberMap extraElementsMemberMap)
 {
     if (extraElementsMemberMap.MemberType == typeof(BsonDocument))
     {
         var extraElements = (BsonDocument)extraElementsMemberMap.Getter(obj);
         if (extraElements == null)
         {
             extraElements = new BsonDocument();
             extraElementsMemberMap.Setter(obj, extraElements);
         }
         var bsonValue = BsonValue.ReadFrom(bsonReader);
         extraElements[elementName] = bsonValue;
     }
     else
     {
         var extraElements = (IDictionary <string, object>)extraElementsMemberMap.Getter(obj);
         if (extraElements == null)
         {
             if (extraElementsMemberMap.MemberType == typeof(IDictionary <string, object>))
             {
                 extraElements = new Dictionary <string, object>();
             }
             else
             {
                 extraElements = (IDictionary <string, object>)Activator.CreateInstance(extraElementsMemberMap.MemberType);
             }
             extraElementsMemberMap.Setter(obj, extraElements);
         }
         var bsonValue = BsonValue.ReadFrom(bsonReader);
         extraElements[elementName] = BsonTypeMapper.MapToDotNetValue(bsonValue);
     }
 }
        /// <summary>
        /// Gets the actual type of an object by reading the discriminator from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The reader.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <returns>The actual type.</returns>
        public Type GetActualType(
            BsonReader bsonReader,
            Type nominalType
            )
        {
            // the BsonReader is sitting at the value whose actual type needs to be found
            var bsonType = bsonReader.CurrentBsonType;

            if (bsonReader.State == BsonReaderState.Value)
            {
                Type primitiveType = null;
                switch (bsonType)
                {
                case BsonType.Boolean: primitiveType = typeof(bool); break;

                case BsonType.Binary:
                    var               bookmark = bsonReader.GetBookmark();
                    byte[]            bytes;
                    BsonBinarySubType subType;
                    bsonReader.ReadBinaryData(out bytes, out subType);
                    if (subType == BsonBinarySubType.Uuid && bytes.Length == 16)
                    {
                        primitiveType = typeof(Guid);
                    }
                    bsonReader.ReturnToBookmark(bookmark);
                    break;

                case BsonType.DateTime: primitiveType = typeof(DateTime); break;

                case BsonType.Double: primitiveType = typeof(double); break;

                case BsonType.Int32: primitiveType = typeof(int); break;

                case BsonType.Int64: primitiveType = typeof(long); break;

                case BsonType.ObjectId: primitiveType = typeof(ObjectId); break;

                case BsonType.String: primitiveType = typeof(string); break;
                }

                if (primitiveType != null && nominalType.IsAssignableFrom(primitiveType))
                {
                    return(primitiveType);
                }
            }

            if (bsonType == BsonType.Document)
            {
                var bookmark = bsonReader.GetBookmark();
                bsonReader.ReadStartDocument();
                var actualType = nominalType;
                if (bsonReader.FindElement(elementName))
                {
                    var discriminator = BsonValue.ReadFrom(bsonReader);
                    if (discriminator.IsBsonArray)
                    {
                        discriminator = discriminator.AsBsonArray.Last(); // last item is leaf class discriminator
                    }
                    actualType = BsonDefaultSerializer.LookupActualType(nominalType, discriminator);
                }
                bsonReader.ReturnToBookmark(bookmark);
                return(actualType);
            }

            return(nominalType);
        }
Exemplo n.º 12
0
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BsonDateTime));
            var dateTimeSerializationOptions = EnsureSerializationOptions <DateTimeSerializationOptions>(options);

            var bsonType = bsonReader.GetCurrentBsonType();

            if (bsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                long?millisecondsSinceEpoch = null;
                long?ticks = null;
                switch (bsonType)
                {
                case BsonType.DateTime:
                    millisecondsSinceEpoch = bsonReader.ReadDateTime();
                    break;

                case BsonType.Document:
                    bsonReader.ReadStartDocument();
                    millisecondsSinceEpoch = bsonReader.ReadDateTime("DateTime");
                    bsonReader.ReadName("Ticks");
                    var ticksValue = BsonValue.ReadFrom(bsonReader);
                    if (!ticksValue.IsBsonUndefined)
                    {
                        ticks = ticksValue.ToInt64();
                    }
                    bsonReader.ReadEndDocument();
                    break;

                case BsonType.Int64:
                    ticks = bsonReader.ReadInt64();
                    break;

                case BsonType.String:
                    // note: we're not using XmlConvert because of bugs in Mono
                    DateTime dateTime;
                    if (dateTimeSerializationOptions.DateOnly)
                    {
                        dateTime = DateTime.SpecifyKind(DateTime.ParseExact(bsonReader.ReadString(), "yyyy-MM-dd", null), DateTimeKind.Utc);
                    }
                    else
                    {
                        var formats = new string[] { "yyyy-MM-ddK", "yyyy-MM-ddTHH:mm:ssK", "yyyy-MM-ddTHH:mm:ss.FFFFFFFK", };
                        dateTime = DateTime.ParseExact(bsonReader.ReadString(), formats, null, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
                    }
                    ticks = dateTime.Ticks;
                    break;

                default:
                    var message = string.Format("Cannot deserialize DateTime from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
                }

                BsonDateTime bsonDateTime;
                if (ticks.HasValue)
                {
                    bsonDateTime = BsonDateTime.Create(new DateTime(ticks.Value, DateTimeKind.Utc));
                }
                else
                {
                    bsonDateTime = BsonDateTime.Create(millisecondsSinceEpoch.Value);
                }

                if (dateTimeSerializationOptions.DateOnly)
                {
                    var dateTime = bsonDateTime.Value;
                    if (dateTime.TimeOfDay != TimeSpan.Zero)
                    {
                        throw new FileFormatException("TimeOfDay component for DateOnly DateTime value is not zero.");
                    }
                    bsonDateTime = BsonDateTime.Create(DateTime.SpecifyKind(dateTime, dateTimeSerializationOptions.Kind)); // not ToLocalTime or ToUniversalTime!
                }
                else
                {
                    if (bsonDateTime.IsValidDateTime)
                    {
                        var dateTime = bsonDateTime.Value;
                        switch (dateTimeSerializationOptions.Kind)
                        {
                        case DateTimeKind.Local:
                        case DateTimeKind.Unspecified:
                            dateTime = DateTime.SpecifyKind(BsonUtils.ToLocalTime(dateTime), dateTimeSerializationOptions.Kind);
                            break;

                        case DateTimeKind.Utc:
                            dateTime = BsonUtils.ToUniversalTime(dateTime);
                            break;
                        }
                        bsonDateTime = BsonDateTime.Create(dateTime);
                    }
                    else
                    {
                        if (dateTimeSerializationOptions.Kind != DateTimeKind.Utc)
                        {
                            throw new FileFormatException("BsonDateTime is outside the range of .NET DateTime.");
                        }
                    }
                }

                return(bsonDateTime);
            }
        }
Exemplo n.º 13
0
        // public methods
        /// <summary>
        /// Gets the actual type of an object by reading the discriminator from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The reader.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <returns>The actual type.</returns>
        public Type GetActualType(BsonReader bsonReader, Type nominalType)
        {
            // the BsonReader is sitting at the value whose actual type needs to be found
            var bsonType = bsonReader.GetCurrentBsonType();

            if (bsonReader.State == BsonReaderState.Value)
            {
                Type primitiveType = null;
                switch (bsonType)
                {
                case BsonType.Boolean: primitiveType = typeof(bool); break;

                case BsonType.Binary:
                    var               bookmark = bsonReader.GetBookmark();
                    byte[]            bytes;
                    BsonBinarySubType subType;
                    bsonReader.ReadBinaryData(out bytes, out subType);
                    if (subType == BsonBinarySubType.UuidStandard || subType == BsonBinarySubType.UuidLegacy)
                    {
                        primitiveType = typeof(Guid);
                    }
                    bsonReader.ReturnToBookmark(bookmark);
                    break;

                case BsonType.DateTime: primitiveType = typeof(DateTime); break;

                case BsonType.Double: primitiveType = typeof(double); break;

                case BsonType.Int32: primitiveType = typeof(int); break;

                case BsonType.Int64: primitiveType = typeof(long); break;

                case BsonType.ObjectId: primitiveType = typeof(ObjectId); break;

                case BsonType.String: primitiveType = typeof(string); break;
                }

                // Type.IsAssignableFrom is extremely expensive, always perform a direct type check before calling Type.IsAssignableFrom
                if (primitiveType != null && (primitiveType == nominalType || nominalType.IsAssignableFrom(primitiveType)))
                {
                    return(primitiveType);
                }
            }

            if (bsonType == BsonType.Document)
            {
                // ensure KnownTypes of nominalType are registered (so IsTypeDiscriminated returns correct answer)
                BsonSerializer.EnsureKnownTypesAreRegistered(nominalType);

                // we can skip looking for a discriminator if nominalType has no discriminated sub types
                if (BsonSerializer.IsTypeDiscriminated(nominalType))
                {
                    var bookmark = bsonReader.GetBookmark();
                    bsonReader.ReadStartDocument();
                    var actualType = nominalType;
                    if (bsonReader.FindElement(_elementName))
                    {
                        var discriminator = BsonValue.ReadFrom(bsonReader);
                        if (discriminator.IsBsonArray)
                        {
                            discriminator = discriminator.AsBsonArray.Last(); // last item is leaf class discriminator
                        }
                        actualType = BsonSerializer.LookupActualType(nominalType, discriminator);
                    }
                    bsonReader.ReturnToBookmark(bookmark);
                    return(actualType);
                }
            }

            return(nominalType);
        }
        // explicit interface implementation
        object IBsonSerializable.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
        {
            if (bsonReader.CurrentBsonType == Bson.BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                bsonReader.ReadStartDocument();
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    var name = bsonReader.ReadName();
                    switch (name)
                    {
                    case "abbreviated":
                        abbreviated = bsonReader.ReadString();
                        break;

                    case "client":
                        client = bsonReader.ReadString();
                        break;

                    case "command":
                        command = BsonDocument.ReadFrom(bsonReader);
                        break;

                    case "cursorid":
                        cursorId = BsonValue.ReadFrom(bsonReader).ToInt64();
                        break;

                    case "err":
                        error = bsonReader.ReadString();
                        break;

                    case "exception":
                        exception = bsonReader.ReadString();
                        break;

                    case "exceptionCode":
                        exceptionCode = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "exhaust":
                        exhaust = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "fastmod":
                        fastMod = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "fastmodinsert":
                        fastModInsert = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "idhack":
                        idHack = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "info":
                        info = bsonReader.ReadString();
                        break;

                    case "keyUpdates":
                        keyUpdates = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "millis":
                        duration = TimeSpan.FromMilliseconds(BsonValue.ReadFrom(bsonReader).ToDouble());
                        break;

                    case "moved":
                        moved = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "nreturned":
                        numberReturned = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "ns":
                        @namespace = bsonReader.ReadString();
                        break;

                    case "nscanned":
                        numberScanned = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "ntoreturn":
                        numberToReturn = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "ntoskip":
                        numberToSkip = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "op":
                        op = bsonReader.ReadString();
                        break;

                    case "query":
                        query = BsonDocument.ReadFrom(bsonReader);
                        break;

                    case "responseLength":
                        responseLength = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "scanAndOrder":
                        scanAndOrder = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "ts":
                        timestamp = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(bsonReader.ReadDateTime());
                        break;

                    case "updateobj":
                        updateObject = BsonDocument.ReadFrom(bsonReader);
                        break;

                    case "upsert":
                        upsert = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "user":
                        user = bsonReader.ReadString();
                        break;

                    default:
                        break;     // ignore unknown elements
                    }
                }
                bsonReader.ReadEndDocument();
                return(this);
            }
        }
Exemplo n.º 15
0
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(SystemProfileInfo));

            if (bsonReader.GetCurrentBsonType() == Bson.BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                var profileInfo = new SystemProfileInfo();

                bsonReader.ReadStartDocument();
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    var name = bsonReader.ReadName();
                    switch (name)
                    {
                    case "abbreviated":
                        profileInfo.Abbreviated = bsonReader.ReadString();
                        break;

                    case "client":
                        profileInfo.Client = bsonReader.ReadString();
                        break;

                    case "command":
                        profileInfo.Command = BsonDocument.ReadFrom(bsonReader);
                        break;

                    case "cursorid":
                        profileInfo.CursorId = BsonValue.ReadFrom(bsonReader).ToInt64();
                        break;

                    case "err":
                        profileInfo.Error = bsonReader.ReadString();
                        break;

                    case "exception":
                        profileInfo.Exception = bsonReader.ReadString();
                        break;

                    case "exceptionCode":
                        profileInfo.ExceptionCode = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "exhaust":
                        profileInfo.Exhaust = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "fastmod":
                        profileInfo.FastMod = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "fastmodinsert":
                        profileInfo.FastModInsert = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "idhack":
                        profileInfo.IdHack = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "info":
                        profileInfo.Info = bsonReader.ReadString();
                        break;

                    case "keyUpdates":
                        profileInfo.KeyUpdates = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "millis":
                        profileInfo.Duration = TimeSpan.FromMilliseconds(BsonValue.ReadFrom(bsonReader).ToDouble());
                        break;

                    case "moved":
                        profileInfo.Moved = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "nreturned":
                        profileInfo.NumberReturned = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "ns":
                        profileInfo.Namespace = bsonReader.ReadString();
                        break;

                    case "nscanned":
                        profileInfo.NumberScanned = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "ntoreturn":
                        profileInfo.NumberToReturn = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "ntoskip":
                        profileInfo.NumberToSkip = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "op":
                        profileInfo.Op = bsonReader.ReadString();
                        break;

                    case "query":
                        profileInfo.Query = BsonDocument.ReadFrom(bsonReader);
                        break;

                    case "responseLength":
                        profileInfo.ResponseLength = BsonValue.ReadFrom(bsonReader).ToInt32();
                        break;

                    case "scanAndOrder":
                        profileInfo.ScanAndOrder = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "ts":
                        profileInfo.Timestamp = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(bsonReader.ReadDateTime());
                        break;

                    case "updateobj":
                        profileInfo.UpdateObject = BsonDocument.ReadFrom(bsonReader);
                        break;

                    case "upsert":
                        profileInfo.Upsert = BsonValue.ReadFrom(bsonReader).ToBoolean();
                        break;

                    case "user":
                        profileInfo.User = bsonReader.ReadString();
                        break;

                    default:
                        break;     // ignore unknown elements
                    }
                }
                bsonReader.ReadEndDocument();

                return(profileInfo);
            }
        }