当前位置: 首页>>代码示例>>C#>>正文


C# BsonBinaryReader.ReadBsonType方法代码示例

本文整理汇总了C#中MongoDB.Bson.IO.BsonBinaryReader.ReadBsonType方法的典型用法代码示例。如果您正苦于以下问题:C# BsonBinaryReader.ReadBsonType方法的具体用法?C# BsonBinaryReader.ReadBsonType怎么用?C# BsonBinaryReader.ReadBsonType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB.Bson.IO.BsonBinaryReader的用法示例。


在下文中一共展示了BsonBinaryReader.ReadBsonType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestBsonAwesome

 public void TestBsonAwesome()
 {
     string byteString = @"1\x00\x00\x00\x04BSON\x00&\x00\x00\x00\x020\x00\x08\x00\x00\x00awesome\x00\x011\x00333333\[email protected]\x102\x00\xc2\x07\x00\x00\x00\x00";
     byte[] bytes = DecodeByteString(byteString);
     MemoryStream stream = new MemoryStream(bytes);
     using (BsonReader bsonReader = new BsonBinaryReader(stream))
     {
         bsonReader.ReadStartDocument();
         Assert.AreEqual(BsonType.Array, bsonReader.ReadBsonType());
         Assert.AreEqual("BSON", bsonReader.ReadName());
         bsonReader.ReadStartArray();
         Assert.AreEqual(BsonType.String, bsonReader.ReadBsonType());
         Assert.AreEqual("awesome", bsonReader.ReadString());
         Assert.AreEqual(BsonType.Double, bsonReader.ReadBsonType());
         Assert.AreEqual(5.05, bsonReader.ReadDouble());
         Assert.AreEqual(BsonType.Int32, bsonReader.ReadBsonType());
         Assert.AreEqual(1986, bsonReader.ReadInt32());
         bsonReader.ReadEndArray();
         bsonReader.ReadEndDocument();
     }
 }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:21,代码来源:BsonBinaryReaderTests.cs

示例2: TestHelloWorld

 public void TestHelloWorld()
 {
     string byteString = @"\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00";
     byte[] bytes = DecodeByteString(byteString);
     var stream = new MemoryStream(bytes);
     using (var bsonReader = new BsonBinaryReader(stream))
     {
         bsonReader.ReadStartDocument();
         Assert.AreEqual(BsonType.String, bsonReader.ReadBsonType());
         Assert.AreEqual("hello", bsonReader.ReadName());
         Assert.AreEqual("world", bsonReader.ReadString());
         bsonReader.ReadEndDocument();
     }
 }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:14,代码来源:BsonBinaryReaderTests.cs

示例3: GetElement

        /// <summary>
        /// Gets an element of this document.
        /// </summary>
        /// <param name="index">The zero based index of the element.</param>
        /// <returns>
        /// The element.
        /// </returns>
        public override BsonElement GetElement(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            ThrowIfDisposed();

            using (var stream = new ByteBufferStream(_slice, ownsBuffer: false))
            using (var bsonReader = new BsonBinaryReader(stream, _readerSettings))
            {
                var context = BsonDeserializationContext.CreateRoot(bsonReader);
                
                bsonReader.ReadStartDocument();
                var i = 0;
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    if (i == index)
                    {
                        var name = bsonReader.ReadName();
                        var value = DeserializeBsonValue(context);
                        return new BsonElement(name, value);
                    }

                    bsonReader.SkipName();
                    bsonReader.SkipValue();
                    i++;
                }
                bsonReader.ReadEndDocument();

                throw new ArgumentOutOfRangeException("index");
            }
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:40,代码来源:RawBsonDocument.cs

示例4: Contains

        /// <summary>
        /// Tests whether the document contains an element with the specified name.
        /// </summary>
        /// <param name="name">The name of the element to look for.</param>
        /// <returns>
        /// True if the document contains an element with the specified name.
        /// </returns>
        public override bool Contains(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            ThrowIfDisposed();

            using (var stream = new ByteBufferStream(_slice, ownsBuffer: false))
            using (var bsonReader = new BsonBinaryReader(stream, _readerSettings))
            {
                bsonReader.ReadStartDocument();
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    if (bsonReader.ReadName() == name)
                    {
                        return true;
                    }
                    bsonReader.SkipValue();
                }
                bsonReader.ReadEndDocument();

                return false;
            }
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:32,代码来源:RawBsonDocument.cs

示例5: IndexOf

        /// <summary>
        /// Gets the index of a value in the array.
        /// </summary>
        /// <param name="value">The value to search for.</param>
        /// <param name="index">The zero based index at which to start the search.</param>
        /// <param name="count">The number of elements to search.</param>
        /// <returns>The zero based index of the value (or -1 if not found).</returns>
        public override int IndexOf(BsonValue value, int index, int count)
        {
            ThrowIfDisposed();
            using (var bsonReader = new BsonBinaryReader(new BsonBuffer(CloneSlice(), false), true, _readerSettings))
            {
                bsonReader.ReadStartDocument();
                var i = 0;
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    bsonReader.SkipName();
                    if (i >= index)
                    {
                        if (count == 0)
                        {
                            return -1;
                        }

                        if (DeserializeBsonValue(bsonReader).Equals(value))
                        {
                            return i;
                        }

                        count--;
                    }
                    else
                    {
                        bsonReader.SkipValue();
                    }

                    i++;
                }
                bsonReader.ReadEndDocument();

                return -1;
            }
        }
开发者ID:RoninWest,项目名称:mongo-csharp-driver,代码行数:43,代码来源:RawBsonArray.cs

示例6: Contains

        /// <summary>
        /// Tests whether the array contains a value.
        /// </summary>
        /// <param name="value">The value to test for.</param>
        /// <returns>True if the array contains the value.</returns>
        public override bool Contains(BsonValue value)
        {
            ThrowIfDisposed();
            using (var stream = new ByteBufferStream(_slice, ownsBuffer: false))
            using (var bsonReader = new BsonBinaryReader(stream, _readerSettings))
            {
                var context = BsonDeserializationContext.CreateRoot(bsonReader);

                bsonReader.ReadStartDocument();
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    bsonReader.SkipName();
                    if (DeserializeBsonValue(context).Equals(value))
                    {
                        return true;
                    }
                }
                bsonReader.ReadEndDocument();

                return false;
            }
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:27,代码来源:RawBsonArray.cs

示例7: GetEnumerator

        /// <summary>
        /// Gets an enumerator that can enumerate the elements of the array.
        /// </summary>
        /// <returns>An enumerator.</returns>
        public override IEnumerator<BsonValue> GetEnumerator()
        {
            ThrowIfDisposed();
            using (var stream = new ByteBufferStream(_slice, ownsBuffer: false))
            using (var bsonReader = new BsonBinaryReader(stream, _readerSettings))
            {
                var context = BsonDeserializationContext.CreateRoot(bsonReader);

                bsonReader.ReadStartDocument();
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    bsonReader.SkipName();
                    yield return DeserializeBsonValue(context);
                }
                bsonReader.ReadEndDocument();
            }
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:21,代码来源:RawBsonArray.cs

示例8: DeserializeThisLevel

        private void DeserializeThisLevel()
        {
            var elements = new List<BsonElement>();

            using (var bsonReader = new BsonBinaryReader(new BsonBuffer(CloneSlice(), true), true, _readerSettings))
            {
                bsonReader.ReadStartDocument();
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    var name = bsonReader.ReadName();
                    BsonValue value;
                    switch (bsonType)
                    {
                        case BsonType.Array: value = DeserializeLazyBsonArray(bsonReader); break;
                        case BsonType.Document: value = DeserializeLazyBsonDocument(bsonReader); break;
                        default: value = (BsonValue)BsonValueSerializer.Instance.Deserialize(bsonReader, typeof(BsonValue), null); break;
                    }
                    elements.Add(new BsonElement(name, value));
                }
                bsonReader.ReadEndDocument();
            }

            var slice = _slice;
            try
            {
                _slice = null;
                AddRange(elements);
                slice.Dispose();
            }
            catch
            {
                try { Clear(); } catch { }
                _slice = slice;
                throw;
            }
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:37,代码来源:LazyBsonDocument.cs

示例9: ArgumentOutOfRangeException

        // public indexers
        /// <summary>
        /// Gets or sets a value by position.
        /// </summary>
        /// <param name="index">The position.</param>
        /// <returns>The value.</returns>
        public override BsonValue this[int index]
        {
            get
            {
                if (index < 0)
                {
                    throw new ArgumentOutOfRangeException("index");
                }
                ThrowIfDisposed();

                using (var bsonReader = new BsonBinaryReader(new BsonBuffer(CloneSlice(), false), true, _readerSettings))
                {
                    bsonReader.ReadStartDocument();
                    var i = 0;
                    while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                    {
                        bsonReader.SkipName();
                        if (i == index)
                        {
                            return DeserializeBsonValue(bsonReader);
                        }

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

                    throw new ArgumentOutOfRangeException("index");
                }
            }
            set
            {
                throw new NotSupportedException("RawBsonArray instances are immutable.");
            }
        }
开发者ID:RoninWest,项目名称:mongo-csharp-driver,代码行数:41,代码来源:RawBsonArray.cs

示例10: GetValue

        /// <summary>
        /// Gets the value of an element.
        /// </summary>
        /// <param name="index">The zero based index of the element.</param>
        /// <returns>
        /// The value of the element.
        /// </returns>
        public override BsonValue GetValue(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            ThrowIfDisposed();

            using (var bsonReader = new BsonBinaryReader(new BsonBuffer(CloneSlice(), true), true, _readerSettings))
            {
                bsonReader.ReadStartDocument();
                var i = 0;
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    bsonReader.SkipName();
                    if (i == index)
                    {
                        return DeserializeBsonValue(bsonReader);
                    }

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

                throw new ArgumentOutOfRangeException("index");
            }
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:35,代码来源:RawBsonDocument.cs

示例11: TryGetValue

        /// <summary>
        /// Tries to get the value of an element of this document.
        /// </summary>
        /// <param name="name">The name of the element.</param>
        /// <param name="value">The value of the element.</param>
        /// <returns>
        /// True if an element with that name was found.
        /// </returns>
        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;
            }
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:30,代码来源:RawBsonDocument.cs

示例12: MaterializeThisLevel

        private IEnumerable<BsonElement> MaterializeThisLevel()
        {
            var elements = new List<BsonElement>();

            using (var stream = new ByteBufferStream(_slice, ownsBuffer: false))
            using (var bsonReader = new BsonBinaryReader(stream, _readerSettings))
            {
                var context = BsonDeserializationContext.CreateRoot(bsonReader);

                bsonReader.ReadStartDocument();
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    var name = bsonReader.ReadName();
                    BsonValue value;
                    switch (bsonType)
                    {
                        case BsonType.Array: value = DeserializeLazyBsonArray(bsonReader); break;
                        case BsonType.Document: value = DeserializeLazyBsonDocument(bsonReader); break;
                        default: value = BsonValueSerializer.Instance.Deserialize(context); break;
                    }
                    elements.Add(new BsonElement(name, value));
                }
                bsonReader.ReadEndDocument();
            }

            return elements;
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:28,代码来源:LazyBsonDocument.cs

示例13: MaterializeThisLevel

        private IEnumerable<BsonValue> MaterializeThisLevel()
        {
            var values = new List<BsonValue>();
            var readerSettings = _readerSettings.Clone();
            readerSettings.MaxDocumentSize = _slice.Length;

            using (var bsonReader = new BsonBinaryReader(new BsonBuffer(CloneSlice(), true), true, readerSettings))
            {
                bsonReader.ReadStartDocument();
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    bsonReader.SkipName();
                    BsonValue value;
                    switch (bsonType)
                    {
                        case BsonType.Array: value = DeserializeLazyBsonArray(bsonReader); break;
                        case BsonType.Document: value = DeserializeLazyBsonDocument(bsonReader); break;
                        default: value = (BsonValue)BsonValueSerializer.Instance.Deserialize(bsonReader, typeof(BsonValue), null); break;
                    }
                    values.Add(value);
                }
                bsonReader.ReadEndDocument();
            }

            return values;
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:27,代码来源:LazyBsonArray.cs

示例14: MaterializeThisLevel

        private IEnumerable<BsonElement> MaterializeThisLevel()
        {
            var elements = new List<BsonElement>();

            using (var bsonReader = new BsonBinaryReader(new BsonBuffer(CloneSlice(), true), true, _readerSettings))
            {
                bsonReader.ReadStartDocument();
                BsonType bsonType;
                while ((bsonType = bsonReader.ReadBsonType()) != BsonType.EndOfDocument)
                {
                    var name = bsonReader.ReadName();
                    BsonValue value;
                    switch (bsonType)
                    {
                        case BsonType.Array: value = DeserializeLazyBsonArray(bsonReader); break;
                        case BsonType.Document: value = DeserializeLazyBsonDocument(bsonReader); break;
                        default: value = (BsonValue)BsonValueSerializer.Instance.Deserialize(bsonReader, typeof(BsonValue), null); break;
                    }
                    elements.Add(new BsonElement(name, value));
                }
                bsonReader.ReadEndDocument();
            }

            return elements;
        }
开发者ID:neo2018,项目名称:mongo-csharp-driver,代码行数:25,代码来源:LazyBsonDocument.cs

示例15: TryGetValue

        /// <summary>
        /// Tries to get the value of an element of this document.
        /// </summary>
        /// <param name="name">The name of the element.</param>
        /// <param name="value">The value of the element.</param>
        /// <returns>
        /// True if an element with that name was found.
        /// </returns>
        public override bool TryGetValue(string name, out BsonValue value)
        {
            ThrowIfDisposed();
            using (var stream = new ByteBufferStream(_slice, ownsBuffer: false))
            using (var bsonReader = new BsonBinaryReader(stream, _readerSettings))
            {
                var context = BsonDeserializationContext.CreateRoot(bsonReader);
                
                bsonReader.ReadStartDocument();
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    if (bsonReader.ReadName() == name)
                    {
                        value = DeserializeBsonValue(context);
                        return true;
                    }

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

                value = null;
                return false;
            }
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:33,代码来源:RawBsonDocument.cs


注:本文中的MongoDB.Bson.IO.BsonBinaryReader.ReadBsonType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。