本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.Bson.BsonWriter.WriteObjectId方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteObjectId方法的具体用法?C# BsonWriter.WriteObjectId怎么用?C# BsonWriter.WriteObjectId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.Bson.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteObjectId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteOidPlusContent
public void WriteOidPlusContent()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartObject();
writer.WritePropertyName("_id");
writer.WriteObjectId(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"));
writer.WritePropertyName("test");
writer.WriteValue("1234£56");
writer.WriteEndObject();
byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
CollectionAssert.AreEquivalent(expected, ms.ToArray());
}
示例2: WriteOid
public void WriteOid()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
byte[] oid = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
writer.WriteStartObject();
writer.WritePropertyName("_oid");
writer.WriteObjectId(oid);
writer.WriteEndObject();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
Assert.AreEqual("17-00-00-00-07-5F-6F-69-64-00-01-02-03-04-05-06-07-08-09-0A-0B-0C-00", bson);
ms.Seek(0, SeekOrigin.Begin);
BsonReader reader = new BsonReader(ms);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
CollectionAssert.AreEquivalent(oid, (byte[])reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
}