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


C# IBsonReader.ReadBsonType方法代码示例

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


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

示例1: TestArrayEmpty

 public void TestArrayEmpty()
 {
     var json = "[]";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Array, _bsonReader.ReadBsonType());
         _bsonReader.ReadStartArray();
         Assert.Equal(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
         _bsonReader.ReadEndArray();
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonArray>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:13,代码来源:JsonReaderTests.cs

示例2: GetActualType

 public Type GetActualType(IBsonReader bsonReader, Type nominalType)
 {
     var bookmark = bsonReader.GetBookmark();
     bsonReader.ReadStartDocument();
     var actualType = nominalType;
     while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
     {
         var name = bsonReader.ReadName();
         if (name == "OnlyInB")
         {
             actualType = typeof(B);
             break;
         }
         else if (name == "OnlyInC")
         {
             actualType = typeof(C);
             break;
         }
         bsonReader.SkipValue();
     }
     bsonReader.ReturnToBookmark(bookmark);
     return actualType;
 }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:23,代码来源:MagicDiscriminatorTests.cs

示例3: TestJavaScriptWithScope

 public void TestJavaScriptWithScope()
 {
     string json = "{ \"$code\" : \"function f() { return n; }\", \"$scope\" : { \"n\" : 1 } }";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.JavaScriptWithScope, _bsonReader.ReadBsonType());
         Assert.Equal("function f() { return n; }", _bsonReader.ReadJavaScriptWithScope());
         _bsonReader.ReadStartDocument();
         Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
         Assert.Equal("n", _bsonReader.ReadName());
         Assert.Equal(1, _bsonReader.ReadInt32());
         _bsonReader.ReadEndDocument();
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonJavaScriptWithScope>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:16,代码来源:JsonReaderTests.cs

示例4: TestTimestampConstructor

 public void TestTimestampConstructor()
 {
     var json = "Timestamp(1, 2)";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Timestamp, _bsonReader.ReadBsonType());
         Assert.Equal(new BsonTimestamp(1, 2).Value, _bsonReader.ReadTimestamp());
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonTimestamp>(new StringReader(json)).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:11,代码来源:JsonReaderTests.cs

示例5: TestDateTimeStrict

 public void TestDateTimeStrict()
 {
     var json = "{ \"$date\" : 0 }";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.DateTime, _bsonReader.ReadBsonType());
         Assert.Equal(0, _bsonReader.ReadDateTime());
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     var jsonSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
     Assert.Equal(json, BsonSerializer.Deserialize<DateTime>(json).ToJson(jsonSettings));
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:JsonReaderTests.cs

示例6: TestRegularExpressionShell

 public void TestRegularExpressionShell()
 {
     var json = "/pattern/imxs";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.RegularExpression, _bsonReader.ReadBsonType());
         var regex = _bsonReader.ReadRegularExpression();
         Assert.Equal("pattern", regex.Pattern);
         Assert.Equal("imxs", regex.Options);
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonRegularExpression>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:13,代码来源:JsonReaderTests.cs

示例7: TestStringEmpty

 public void TestStringEmpty()
 {
     var json = "\"\"";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.String, _bsonReader.ReadBsonType());
         Assert.Equal("", _bsonReader.ReadString());
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<string>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:11,代码来源:JsonReaderTests.cs

示例8: TestNestedDocument

 public void TestNestedDocument()
 {
     var json = "{ \"a\" : { \"b\" : 1, \"c\" : 2 } }";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Document, _bsonReader.ReadBsonType());
         _bsonReader.ReadStartDocument();
         Assert.Equal(BsonType.Document, _bsonReader.ReadBsonType());
         Assert.Equal("a", _bsonReader.ReadName());
         _bsonReader.ReadStartDocument();
         Assert.Equal("b", _bsonReader.ReadName());
         Assert.Equal(1, _bsonReader.ReadInt32());
         Assert.Equal("c", _bsonReader.ReadName());
         Assert.Equal(2, _bsonReader.ReadInt32());
         _bsonReader.ReadEndDocument();
         _bsonReader.ReadEndDocument();
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonDocument>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:20,代码来源:JsonReaderTests.cs

示例9: TestObjectIdShell

 public void TestObjectIdShell()
 {
     var json = "ObjectId(\"4d0ce088e447ad08b4721a37\")";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.ObjectId, _bsonReader.ReadBsonType());
         var objectId = _bsonReader.ReadObjectId();
         Assert.Equal("4d0ce088e447ad08b4721a37", objectId.ToString());
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<ObjectId>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:JsonReaderTests.cs

示例10: TestGuid

 public void TestGuid()
 {
     var guid = new Guid("B5F21E0C2A0D42D6AD03D827008D8AB6");
     var json = "CSUUID(\"B5F21E0C2A0D42D6AD03D827008D8AB6\")";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Binary, _bsonReader.ReadBsonType());
         var binaryData = _bsonReader.ReadBinaryData();
         Assert.True(binaryData.Bytes.SequenceEqual(guid.ToByteArray()));
         Assert.Equal(BsonBinarySubType.UuidLegacy, binaryData.SubType);
         Assert.Equal(GuidRepresentation.CSharpLegacy, binaryData.GuidRepresentation);
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     var expected = "CSUUID(\"b5f21e0c-2a0d-42d6-ad03-d827008d8ab6\")";
     Assert.Equal(expected, BsonSerializer.Deserialize<Guid>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:16,代码来源:JsonReaderTests.cs

示例11: TestHexData

 public void TestHexData()
 {
     var expectedBytes = new byte[] { 0x01, 0x23 };
     var json = "HexData(0, \"123\")";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Binary, _bsonReader.ReadBsonType());
         var bytes = _bsonReader.ReadBytes();
         Assert.True(expectedBytes.SequenceEqual(bytes));
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     var expectedJson = "new BinData(0, \"ASM=\")";
     Assert.Equal(expectedJson, BsonSerializer.Deserialize<byte[]>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:14,代码来源:JsonReaderTests.cs

示例12: TestDocumentTwoElements

 public void TestDocumentTwoElements()
 {
     var json = "{ \"x\" : 1, \"y\" : 2 }";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Document, _bsonReader.ReadBsonType());
         _bsonReader.ReadStartDocument();
         Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
         Assert.Equal("x", _bsonReader.ReadName());
         Assert.Equal(1, _bsonReader.ReadInt32());
         Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
         Assert.Equal("y", _bsonReader.ReadName());
         Assert.Equal(2, _bsonReader.ReadInt32());
         Assert.Equal(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
         _bsonReader.ReadEndDocument();
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonDocument>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:19,代码来源:JsonReaderTests.cs

示例13: TestDouble

 public void TestDouble()
 {
     var json = "1.5";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Double, _bsonReader.ReadBsonType());
         Assert.Equal(1.5, _bsonReader.ReadDouble());
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<double>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:11,代码来源:JsonReaderTests.cs

示例14: TestDocumentEmpty

 public void TestDocumentEmpty()
 {
     var json = "{ }";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.Equal(BsonType.Document, _bsonReader.ReadBsonType());
         _bsonReader.ReadStartDocument();
         Assert.Equal(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
         _bsonReader.ReadEndDocument();
         Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
     }
     Assert.Equal(json, BsonSerializer.Deserialize<BsonDocument>(json).ToJson());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:13,代码来源:JsonReaderTests.cs

示例15: TestDecimal128ExtendedJson

 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());
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:10,代码来源:JsonReaderTests.cs


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