Class BsonObjectId
Represents a BSON ObjectId value (see also ObjectId).
[Serializable]
public class BsonObjectId : BsonValue, IComparable<BsonValue>, IConvertible, IEquatable<BsonValue>, IComparable<BsonObjectId>, IEquatable<BsonObjectId>
- Inheritance
-
BsonObjectId
- Implements
- Inherited Members
- Extension Methods
Constructors
BsonObjectId(ObjectId)
Initializes a new instance of the BsonObjectId class.
public BsonObjectId(ObjectId value)
Parameters
value
ObjectIdThe value.
BsonObjectId(byte[])
Initializes a new instance of the BsonObjectId class.
[Obsolete("Use new BsonObjectId(ObjectId value) instead.")]
public BsonObjectId(byte[] bytes)
Parameters
bytes
byte[]The bytes.
BsonObjectId(DateTime, int, short, int)
Initializes a new instance of the BsonObjectId class.
[Obsolete("Use new BsonObjectId(new ObjectId(DateTime timestamp, int machine, short pid, int increment)) instead.")]
public BsonObjectId(DateTime timestamp, int machine, short pid, int increment)
Parameters
timestamp
DateTimeThe timestamp (expressed as a DateTime).
machine
intThe machine hash.
pid
shortThe PID.
increment
intThe increment.
BsonObjectId(int, int, short, int)
Initializes a new instance of the BsonObjectId class.
[Obsolete("Use new BsonObjectId(new ObjectId(int timestamp, int machine, short pid, int increment)) instead.")]
public BsonObjectId(int timestamp, int machine, short pid, int increment)
Parameters
timestamp
intThe timestamp.
machine
intThe machine hash.
pid
shortThe PID.
increment
intThe increment.
BsonObjectId(string)
Initializes a new instance of the BsonObjectId class.
[Obsolete("Use new BsonObjectId(new ObjectId(string value)) instead.")]
public BsonObjectId(string value)
Parameters
value
stringThe value.
Properties
BsonType
Gets the BsonType of this BsonValue.
public override BsonType BsonType { get; }
Property Value
CreationTime
Gets the creation time (derived from the timestamp).
[Obsolete("Use Value.CreationTime instead.")]
public DateTime CreationTime { get; }
Property Value
Empty
Gets an instance of BsonObjectId where the value is empty.
public static BsonObjectId Empty { get; }
Property Value
Increment
Gets the increment.
[Obsolete("Use Value.Increment instead.")]
public int Increment { get; }
Property Value
Machine
Gets the machine.
[Obsolete("This property will be removed in a later release.")]
public int Machine { get; }
Property Value
Pid
Gets the PID.
[Obsolete("This property will be removed in a later release.")]
public short Pid { get; }
Property Value
RawValue
Gets the BsonObjectId as an ObjectId.
[Obsolete("Use Value instead.")]
public override object RawValue { get; }
Property Value
Timestamp
Gets the timestamp.
[Obsolete("Use Value.Timestamp instead.")]
public int Timestamp { get; }
Property Value
Value
Gets the value of this BsonObjectId.
public ObjectId Value { get; }
Property Value
Methods
CompareTo(BsonObjectId)
Compares this BsonObjectId to another BsonObjectId.
public int CompareTo(BsonObjectId other)
Parameters
other
BsonObjectIdThe other BsonObjectId.
Returns
- int
A 32-bit signed integer that indicates whether this BsonObjectId is less than, equal to, or greather than the other.
CompareTo(BsonValue)
Compares the BsonObjectId to another BsonValue.
public override int CompareTo(BsonValue other)
Parameters
other
BsonValueThe other BsonValue.
Returns
- int
A 32-bit signed integer that indicates whether this BsonObjectId is less than, equal to, or greather than the other BsonValue.
Create(object)
Creates a new BsonObjectId.
public static BsonObjectId Create(object value)
Parameters
value
objectAn object to be mapped to a BsonObjectId.
Returns
- BsonObjectId
A BsonObjectId or null.
Equals(BsonObjectId)
Compares this BsonObjectId to another BsonObjectId.
public bool Equals(BsonObjectId rhs)
Parameters
rhs
BsonObjectIdThe other BsonObjectId.
Returns
- bool
True if the two BsonObjectId values are equal.
Equals(object)
Compares this BsonObjectId to another object.
public override bool Equals(object obj)
Parameters
obj
objectThe other object.
Returns
- bool
True if the other object is a BsonObjectId and equal to this one.
GenerateNewId()
Generates a new BsonObjectId with a unique value.
[Obsolete("Use new BsonObjectId(ObjectId.GenerateNewId()) instead.")]
public static BsonObjectId GenerateNewId()
Returns
- BsonObjectId
A BsonObjectId.
GenerateNewId(DateTime)
Generates a new BsonObjectId with a unique value (with the timestamp component based on a given DateTime).
[Obsolete("Use new BsonObjectId(ObjectId.GenerateNewId(DateTime timestamp)) instead.")]
public static BsonObjectId GenerateNewId(DateTime timestamp)
Parameters
timestamp
DateTimeThe timestamp component (expressed as a DateTime).
Returns
- BsonObjectId
A BsonObjectId.
GenerateNewId(int)
Generates a new BsonObjectId with a unique value (with the given timestamp).
[Obsolete("Use new BsonObjectId(ObjectId.GenerateNewId(int timestamp)) instead.")]
public static BsonObjectId GenerateNewId(int timestamp)
Parameters
timestamp
intThe timestamp component.
Returns
- BsonObjectId
A BsonObjectId.
GetHashCode()
Gets the hash code.
public override int GetHashCode()
Returns
- int
The hash code.
IConvertibleToStringImplementation(IFormatProvider)
Implementation of the IConvertible ToString method.
protected override string IConvertibleToStringImplementation(IFormatProvider provider)
Parameters
provider
IFormatProviderThe format provider.
Returns
- string
A string.
Parse(string)
Parses a string and creates a new BsonObjectId.
[Obsolete("Use new BsonObjectId(ObjectId.Parse(string s)) instead.")]
public static BsonObjectId Parse(string s)
Parameters
s
stringThe string value.
Returns
- BsonObjectId
A BsonObjectId.
ToByteArray()
Converts the BsonObjectId to a byte array.
[Obsolete("Use Value.ToByteArray() instead.")]
public byte[] ToByteArray()
Returns
- byte[]
A byte array.
ToString()
Returns a string representation of the value.
public override string ToString()
Returns
- string
A string representation of the value.
TryParse(string, out BsonObjectId)
Tries to parse a string and create a new BsonObjectId.
[Obsolete("Use ObjectId.TryParse instead.")]
public static bool TryParse(string s, out BsonObjectId value)
Parameters
s
stringThe string value.
value
BsonObjectIdThe new BsonObjectId.
Returns
- bool
True if the string was parsed successfully.
Operators
operator ==(BsonObjectId, BsonObjectId)
Compares two BsonObjectId values.
public static bool operator ==(BsonObjectId lhs, BsonObjectId rhs)
Parameters
lhs
BsonObjectIdThe first BsonObjectId.
rhs
BsonObjectIdThe other BsonObjectId.
Returns
- bool
True if the two BsonObjectId values are equal according to ==.
implicit operator BsonObjectId(ObjectId)
Converts an ObjectId to a BsonObjectId.
public static implicit operator BsonObjectId(ObjectId value)
Parameters
value
ObjectIdAn ObjectId.
Returns
- BsonObjectId
A BsonObjectId.
operator !=(BsonObjectId, BsonObjectId)
Compares two BsonObjectId values.
public static bool operator !=(BsonObjectId lhs, BsonObjectId rhs)
Parameters
lhs
BsonObjectIdThe first BsonObjectId.
rhs
BsonObjectIdThe other BsonObjectId.
Returns
- bool
True if the two BsonObjectId values are not equal according to ==.