MongoDB.Bson.Serialization.Serializers.BsonObjectIdSerializer.Serialize C# (CSharp) Method

Serialize() public method

Serializes an object to a BsonWriter.
public Serialize ( BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options ) : void
bsonWriter BsonWriter The BsonWriter.
nominalType System.Type The nominal type.
value object The object.
options IBsonSerializationOptions The serialization options.
return void
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var objectId = ((BsonObjectId)value).Value;
            bsonWriter.WriteObjectId(objectId);
        }
    }