public static BsonDocument SerializeToDocument(object objectToSerialize) { new { objectToSerialize }.Must().NotBeNull(); var document = new BsonDocument(); using (var writer = new BsonDocumentWriter(document)) { BsonSerializer.Serialize(writer, objectToSerialize.GetType(), objectToSerialize); writer.Close(); } return(document); }
public static BsonDocument SerializeToDocument( this object objectToSerialize) { if (objectToSerialize == null) { throw new ArgumentNullException(nameof(objectToSerialize)); } var result = new BsonDocument(); using (var writer = new BsonDocumentWriter(result)) { BsonSerializer.Serialize(writer, objectToSerialize.GetType(), objectToSerialize); writer.Close(); } return(result); }