MongoDB.Bson.IO.BsonWriter.WriteObjectId C# (CSharp) Method

WriteObjectId() public abstract method

Writes a BSON ObjectId to the writer.
public abstract WriteObjectId ( ObjectId objectId ) : void
objectId ObjectId The ObjectId.
return void
        public abstract void WriteObjectId(ObjectId objectId);

Same methods

BsonWriter::WriteObjectId ( int timestamp, int machine, short pid, int increment ) : void
BsonWriter::WriteObjectId ( string name, ObjectId objectId ) : void
BsonWriter::WriteObjectId ( string name, int timestamp, int machine, short pid, int increment ) : void

Usage Example

Example #1
0
 public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     var identity = (Identity)value;
     var objectId = new ObjectId(identity.ToArray());
     BsonType bsonType = options == null ? BsonType.ObjectId : ((RepresentationSerializationOptions)options).Representation;
     switch (bsonType)
     {
         case BsonType.String:
             bsonWriter.WriteString(objectId.ToString());
             break;
         case BsonType.ObjectId:
             bsonWriter.WriteObjectId(objectId.Timestamp, objectId.Machine, objectId.Pid, objectId.Increment);
             break;
         default:
             throw new BsonSerializationException(string.Format("'{0}' is not a valid representation for type 'Identity'", bsonType));
     }
 }
All Usage Examples Of MongoDB.Bson.IO.BsonWriter::WriteObjectId