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


C# ObjectId.ToByteArray方法代码示例

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


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

示例1: TestByteArrayConstructor

 public void TestByteArrayConstructor()
 {
     byte[] bytes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
     var objectId = new ObjectId(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()));
 }
开发者ID:abolibibelot,项目名称:mongo-csharp-driver,代码行数:13,代码来源:ObjectIdTests.cs

示例2: Deserialize

        public override object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
        {
            switch (bsonReader.CurrentBsonType)
            {
                case BsonType.ObjectId:
                    int timestamp;
                    int machine;
                    short pid;
                    int increment;
                    bsonReader.ReadObjectId(out timestamp, out machine, out pid, out increment);
                    var id = new ObjectId(timestamp, machine, pid, increment);
                    return new Identity(id.ToByteArray());

                case BsonType.String:
                    return new Identity(bsonReader.ReadString());

                default:
                    throw new FormatException(string.Format("Cannot deserialize Identity from BsonType: {0}", bsonReader.CurrentBsonType));
            }
        }
开发者ID:wook815,项目名称:Hermes,代码行数:20,代码来源:IdentitySerializer.cs

示例3: WriteObjectId

        /// <inheritdoc/>
        public override void WriteObjectId(ObjectId value)
        {
            ThrowIfDisposed();
            
            PrepareToWrite(12);

            var segment = _buffer.AccessBackingBytes(_position);
            if (segment.Count >= 12)
            {
                value.ToByteArray(segment.Array, segment.Offset);
            }
            else
            {
                var bytes = value.ToByteArray();
                _buffer.SetBytes(_position, bytes, 0, 12);
            }

            SetPositionAfterWrite(_position + 12);
        }
开发者ID:cihanozhan,项目名称:mongo-csharp-driver,代码行数:20,代码来源:ByteBufferStream.cs

示例4: WriteObjectId

 /// <inheritdoc/>
 public override void WriteObjectId(ObjectId value)
 {
     ThrowIfDisposed();
     value.ToByteArray(_temp, 0);
     _stream.Write(_temp, 0, 12);
 }
开发者ID:ghovander,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonStreamAdapter.cs

示例5: WriteObjectId

 /// <summary>
 /// Writes a BSON ObjectId to the stream.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <exception cref="System.ArgumentNullException">stream</exception>
 public void WriteObjectId(ObjectId value)
 {
     if (_bsonStream != null)
     {
         _bsonStream.WriteBsonObjectId(value);
     }
     else
     {
         var bytes = value.ToByteArray();
         _stream.Write(bytes, 0, 12);
     }
 }
开发者ID:Nakro,项目名称:mongo-csharp-driver,代码行数:17,代码来源:BsonStreamWriter.cs

示例6: PrepareToWrite

        /// <summary>
        /// Writes a BSON ObjectId to the stream.
        /// </summary>
        /// <param name="value">The value.</param>
        void IBsonStream.WriteBsonObjectId(ObjectId value)
        {
            PrepareToWrite(12);

            var segment = _byteBuffer.AccessBackingBytes(_position);
            if (segment.Count >= 12)
            {
                value.GetBytes(segment.Array, segment.Offset);
            }
            else
            {
                var bytes = value.ToByteArray();
                _byteBuffer.WriteBytes(_position, bytes, 0, 12);
            }

            SetPositionAfterWrite(_position + 12);
        }
开发者ID:annikulin,项目名称:code-classifier,代码行数:21,代码来源:ByteBufferStream.cs

示例7: WriteObjectId

        /// <summary>
        /// Writes a BSON ObjectId to the writer.
        /// </summary>
        /// <param name="objectId">The ObjectId.</param>
        public override void WriteObjectId(ObjectId objectId)
        {
            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
            {
                ThrowInvalidState("WriteObjectId", BsonWriterState.Value, BsonWriterState.Initial);
            }

            var bytes = objectId.ToByteArray();

            WriteNameHelper(Name);
            switch (_jsonWriterSettings.OutputMode)
            {
                case JsonOutputMode.Strict:
                    _textWriter.Write("{{ \"$oid\" : \"{0}\" }}", BsonUtils.ToHexString(bytes));
                    break;

                case JsonOutputMode.Shell:
                default:
                    _textWriter.Write("ObjectId(\"{0}\")", BsonUtils.ToHexString(bytes));
                    break;
            }

            State = GetNextState();
        }
开发者ID:stefanocastriotta,项目名称:mongo-csharp-driver,代码行数:29,代码来源:JsonWriter.cs

示例8: Write

 public void Write(ObjectId value)
 {
     this.Write(value.ToByteArray());
 }
开发者ID:AshishVishwakarma,项目名称:LiteDB,代码行数:4,代码来源:ByteWriter.cs

示例9: Write

 public static void Write(this BinaryWriter writer, ObjectId oid)
 {
     writer.Write(oid.ToByteArray());
 }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:4,代码来源:BinaryWriterExtensions.cs


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