[CSHARP-568] Improvements to BsonObjectId class Created: 10/Sep/12  Updated: 14/May/14  Resolved: 10/Dec/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.7
Fix Version/s: 1.8

Type: Improvement Priority: Minor - P4
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change

 Description   

Remove all properties and methods from BsonObjectId that do nothing but forward to the method of the same name in ObjectId. This class is a BsonValue wrapper around an ObjectId value, and there is no need to clutter this class's interface with ObjectId methods, and their presence is just confusing because they make this class look sort of like an ObjectId when it's not.

These are the properties and methods to remove:

public BsonObjectId(byte[] bytes)
public BsonObjectId(DateTime timestamp, int machine, short pid, int increment)
public BsonObjectId(int timestamp, int machine, short pid, int increment)
public BsonObjectId(string value)
public int Timestamp { get; }
public int Machine { get; }
public short Pid { get; }
public int Increment { get; }
public DateTime CreationTime { get; }
public static BsonObjectId GenerateNewId()
public static BsonObjectId GenerateNewId(DateTime timestamp)
public static BsonObjectId GenerateNewId(int timestamp)
public static BsonObjectId Parse(string s)
public static bool TryParse(string s, out BsonObjectId value)
public byte[] ToByteArray()

Sample workarounds (where v is BsonObjectId):

// instead of:
var v = BsonObjectId.GenerateNewId();
// use either:
var v = new BsonObjectId(ObjectId.GenerateNewId());
var v = (BsonObjectId)ObjectId.GenerateNewId();
 
// instead of:
var v = BsonObjectId.Parse(s);
// use:
var v = new BsonObjectId(ObjectId.Parse(s));
 
// instead of:
var dt = v.CreationtTime;
// use:
var dt = v.Value.CreationTime;



 Comments   
Comment by auto [ 10/Dec/12 ]

Author:

{u'date': u'2012-12-08T03:49:07Z', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-568: Simplify BsonObjectId class.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/91364b5d8b8b31a741f37348d41dfe6f5f39cded

Comment by Robert Stam [ 07/Dec/12 ]

Reopened to backport to 1.8.

Comment by auto [ 12/Sep/12 ]

Author:

{u'date': u'2012-09-12T11:46:09-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-568: added back in BsonObjectId.Empty
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/bb8fe51ab8c2120bc0b753398624ca1e6b1cefc0

Comment by auto [ 12/Sep/12 ]

Author:

{u'date': u'2012-09-11T09:14:05-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-568: removed redundant properties and methods from BsonObjectId.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/5ef96236a84bcd2f637d7915b91b3edda4cd3a33

Generated at Wed Feb 07 21:37:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.