本文整理汇总了C#中IBsonReader.ReadInt32方法的典型用法代码示例。如果您正苦于以下问题:C# IBsonReader.ReadInt32方法的具体用法?C# IBsonReader.ReadInt32怎么用?C# IBsonReader.ReadInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBsonReader
的用法示例。
在下文中一共展示了IBsonReader.ReadInt32方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestArrayTwoElements
public void TestArrayTwoElements()
{
var json = "[1, 2]";
using (_bsonReader = new JsonReader(json))
{
Assert.Equal(BsonType.Array, _bsonReader.ReadBsonType());
_bsonReader.ReadStartArray();
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
Assert.Equal(1, _bsonReader.ReadInt32());
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
Assert.Equal(2, _bsonReader.ReadInt32());
Assert.Equal(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
_bsonReader.ReadEndArray();
Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
}
Assert.Equal(json, BsonSerializer.Deserialize<BsonArray>(json).ToJson());
}
示例2: 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());
}
示例3: 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());
}
示例4: TestInt32Constructor
public void TestInt32Constructor(string json)
{
using (_bsonReader = new JsonReader(json))
{
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
Assert.Equal(123, _bsonReader.ReadInt32());
Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
}
var canonicalJson = "123";
Assert.Equal(canonicalJson, BsonSerializer.Deserialize<int>(new StringReader(json)).ToJson());
}
示例5: TestInt32
public void TestInt32()
{
var json = "123";
using (_bsonReader = new JsonReader(json))
{
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
Assert.Equal(123, _bsonReader.ReadInt32());
Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
}
Assert.Equal(json, BsonSerializer.Deserialize<int>(json).ToJson());
}
示例6: 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());
}
示例7: TestBookmark
public void TestBookmark()
{
var json = "{ \"x\" : 1, \"y\" : 2 }";
using (_bsonReader = new JsonReader(json))
{
// do everything twice returning to bookmark in between
var bookmark = _bsonReader.GetBookmark();
Assert.Equal(BsonType.Document, _bsonReader.ReadBsonType());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal(BsonType.Document, _bsonReader.ReadBsonType());
bookmark = _bsonReader.GetBookmark();
_bsonReader.ReadStartDocument();
_bsonReader.ReturnToBookmark(bookmark);
_bsonReader.ReadStartDocument();
bookmark = _bsonReader.GetBookmark();
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
bookmark = _bsonReader.GetBookmark();
Assert.Equal("x", _bsonReader.ReadName());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal("x", _bsonReader.ReadName());
bookmark = _bsonReader.GetBookmark();
Assert.Equal(1, _bsonReader.ReadInt32());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal(1, _bsonReader.ReadInt32());
bookmark = _bsonReader.GetBookmark();
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal(BsonType.Int32, _bsonReader.ReadBsonType());
bookmark = _bsonReader.GetBookmark();
Assert.Equal("y", _bsonReader.ReadName());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal("y", _bsonReader.ReadName());
bookmark = _bsonReader.GetBookmark();
Assert.Equal(2, _bsonReader.ReadInt32());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal(2, _bsonReader.ReadInt32());
bookmark = _bsonReader.GetBookmark();
Assert.Equal(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
_bsonReader.ReturnToBookmark(bookmark);
Assert.Equal(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
bookmark = _bsonReader.GetBookmark();
_bsonReader.ReadEndDocument();
_bsonReader.ReturnToBookmark(bookmark);
_bsonReader.ReadEndDocument();
Assert.Equal(BsonReaderState.Initial, _bsonReader.State);
}
Assert.Equal(json, BsonSerializer.Deserialize<BsonDocument>(json).ToJson());
}