本文整理汇总了C#中BsonObjectId.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# BsonObjectId.ToByteArray方法的具体用法?C# BsonObjectId.ToByteArray怎么用?C# BsonObjectId.ToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonObjectId
的用法示例。
在下文中一共展示了BsonObjectId.ToByteArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestByteArrayConstructor
public void TestByteArrayConstructor()
{
byte[] bytes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
var objectId = new BsonObjectId(bytes);
Assert.AreEqual(0x01020304, objectId.Timestamp);
Assert.AreEqual(0x050607, objectId.Machine);
Assert.AreEqual(0x0809, objectId.Pid);
Assert.AreEqual(0x0a0b0c, objectId.Increment);
Assert.AreEqual(0x05060708090a0b0c, objectId.MachinePidIncrement);
Assert.AreEqual(Bson.UnixEpoch.AddSeconds(0x01020304), objectId.CreationTime);
Assert.AreEqual("0102030405060708090a0b0c", objectId.ToString());
Assert.IsTrue(bytes.SequenceEqual(objectId.ToByteArray()));
}
示例2: TestIntIntShortIntConstructor
public void TestIntIntShortIntConstructor()
{
#pragma warning disable 618
byte[] bytes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
var objectId = new BsonObjectId(0x01020304, 0x050607, 0x0809, 0x0a0b0c);
Assert.AreEqual(0x01020304, objectId.Timestamp);
Assert.AreEqual(0x050607, objectId.Machine);
Assert.AreEqual(0x0809, objectId.Pid);
Assert.AreEqual(0x0a0b0c, objectId.Increment);
Assert.AreEqual(0x050607, objectId.Machine);
Assert.AreEqual(0x0809, objectId.Pid);
Assert.AreEqual(0x0a0b0c, objectId.Increment);
Assert.AreEqual(BsonConstants.UnixEpoch.AddSeconds(0x01020304), objectId.CreationTime);
Assert.AreEqual("0102030405060708090a0b0c", objectId.ToString());
Assert.IsTrue(bytes.SequenceEqual(objectId.ToByteArray()));
#pragma warning restore
}