Improvements to BsonObjectId class

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Minor - P4
    • 1.8
    • Affects Version/s: 1.7
    • Component/s: None
    • None
    • None
    • Minor Change
    • None
    • None
    • None
    • None
    • None
    • None

      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;
      

            Assignee:
            Robert Stam
            Reporter:
            Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: