WriteObjectId() публичный Метод

Writes a BSON ObjectId to the writer.
public WriteObjectId ( ObjectId objectId ) : void
objectId ObjectId The ObjectId.
Результат void
Пример #1
0
 public void TestOneObjectId()
 {
     var document = new BsonDocument();
     using (var writer = new BsonDocumentWriter(document))
     {
         writer.WriteStartDocument();
         writer.WriteObjectId("a", ObjectId.Empty);
         writer.WriteEndDocument();
     }
     var json = document.ToJson();
     var expected = "{ 'a' : ObjectId('000000000000000000000000') }".Replace("'", "\""); ;
     Assert.Equal(expected, json);
 }
 public void TestTwoNestedObjectIds()
 {
     var document = new BsonDocument();
     using (var writer = new BsonDocumentWriter(document))
     {
         writer.WriteStartDocument();
         writer.WriteStartDocument("nested");
         writer.WriteObjectId("a", ObjectId.Empty);
         writer.WriteObjectId("b", ObjectId.Empty);
         writer.WriteEndDocument();
         writer.WriteEndDocument();
     }
     var json = document.ToJson();
     var expected = "{ 'nested' : { 'a' : ObjectId('000000000000000000000000'), 'b' : ObjectId('000000000000000000000000') } }".Replace("'", "\"");
     Assert.AreEqual(expected, json);
 }