MongoDB.Bson.RawBsonDocument.TryGetValue C# (CSharp) Method

TryGetValue() public method

Tries to get the value of an element of this document.
public TryGetValue ( string name, BsonValue &value ) : bool
name string The name of the element.
value BsonValue The value of the element.
return bool
        public override bool TryGetValue(string name, out BsonValue value)
        {
            ThrowIfDisposed();
            using (var bsonReader = new BsonBinaryReader(new BsonBuffer(CloneSlice(), true), true, _readerSettings))
            {
                bsonReader.ReadStartDocument();
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    if (bsonReader.ReadName() == name)
                    {
                        value = DeserializeBsonValue(bsonReader);
                        return true;
                    }

                    bsonReader.SkipValue();
                }
                bsonReader.ReadEndDocument();

                value = null;
                return false;
            }
        }