Struct ObjectId
Represents an ObjectId (see also BsonObjectId).
[Serializable]
public struct ObjectId : IComparable<ObjectId>, IEquatable<ObjectId>, IConvertible
- Implements
- Inherited Members
- Extension Methods
Constructors
ObjectId(byte[])
Initializes a new instance of the ObjectId class.
public ObjectId(byte[] bytes)
Parameters
bytes
byte[]The bytes.
ObjectId(DateTime, int, short, int)
Initializes a new instance of the ObjectId class.
[Obsolete("This constructor will be removed in a later release.")]
public ObjectId(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.
ObjectId(int, int, short, int)
Initializes a new instance of the ObjectId class.
[Obsolete("This constructor will be removed in a later release.")]
public ObjectId(int timestamp, int machine, short pid, int increment)
Parameters
timestamp
intThe timestamp.
machine
intThe machine hash.
pid
shortThe PID.
increment
intThe increment.
ObjectId(string)
Initializes a new instance of the ObjectId class.
public ObjectId(string value)
Parameters
value
stringThe value.
Properties
CreationTime
Gets the creation time (derived from the timestamp).
public DateTime CreationTime { get; }
Property Value
Empty
Gets an instance of ObjectId where the value is empty.
public static ObjectId Empty { get; }
Property Value
Increment
Gets the increment.
[Obsolete("This property will be removed in a later release.")]
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
Timestamp
Gets the timestamp.
public int Timestamp { get; }
Property Value
Methods
CompareTo(ObjectId)
Compares this ObjectId to another ObjectId.
public int CompareTo(ObjectId other)
Parameters
other
ObjectIdThe other ObjectId.
Returns
- int
A 32-bit signed integer that indicates whether this ObjectId is less than, equal to, or greather than the other.
Equals(ObjectId)
Compares this ObjectId to another ObjectId.
public bool Equals(ObjectId rhs)
Parameters
rhs
ObjectIdThe other ObjectId.
Returns
- bool
True if the two ObjectIds are equal.
Equals(object)
Compares this ObjectId to another object.
public override bool Equals(object obj)
Parameters
obj
objectThe other object.
Returns
- bool
True if the other object is an ObjectId and equal to this one.
GenerateNewId()
Generates a new ObjectId with a unique value.
public static ObjectId GenerateNewId()
Returns
- ObjectId
An ObjectId.
GenerateNewId(DateTime)
Generates a new ObjectId with a unique value (with the timestamp component based on a given DateTime).
public static ObjectId GenerateNewId(DateTime timestamp)
Parameters
timestamp
DateTimeThe timestamp component (expressed as a DateTime).
Returns
- ObjectId
An ObjectId.
GenerateNewId(int)
Generates a new ObjectId with a unique value (with the given timestamp).
public static ObjectId GenerateNewId(int timestamp)
Parameters
timestamp
intThe timestamp component.
Returns
- ObjectId
An ObjectId.
GetHashCode()
Gets the hash code.
public override int GetHashCode()
Returns
- int
The hash code.
Pack(int, int, short, int)
Packs the components of an ObjectId into a byte array.
[Obsolete("This method will be removed in a later release.")]
public static byte[] Pack(int timestamp, int machine, short pid, int increment)
Parameters
timestamp
intThe timestamp.
machine
intThe machine hash.
pid
shortThe PID.
increment
intThe increment.
Returns
- byte[]
A byte array.
Parse(string)
Parses a string and creates a new ObjectId.
public static ObjectId Parse(string s)
Parameters
s
stringThe string value.
Returns
- ObjectId
A ObjectId.
ToByteArray()
Converts the ObjectId to a byte array.
public byte[] ToByteArray()
Returns
- byte[]
A byte array.
ToByteArray(byte[], int)
Converts the ObjectId to a byte array.
public void ToByteArray(byte[] destination, int offset)
Parameters
ToString()
Returns a string representation of the value.
public override string ToString()
Returns
- string
A string representation of the value.
TryParse(string, out ObjectId)
Tries to parse a string and create a new ObjectId.
public static bool TryParse(string s, out ObjectId objectId)
Parameters
Returns
- bool
True if the string was parsed successfully.
Unpack(byte[], out int, out int, out short, out int)
Unpacks a byte array into the components of an ObjectId.
[Obsolete("This method will be removed in a later release.")]
public static void Unpack(byte[] bytes, out int timestamp, out int machine, out short pid, out int increment)
Parameters
bytes
byte[]A byte array.
timestamp
intThe timestamp.
machine
intThe machine hash.
pid
shortThe PID.
increment
intThe increment.
Operators
operator ==(ObjectId, ObjectId)
Compares two ObjectIds.
public static bool operator ==(ObjectId lhs, ObjectId rhs)
Parameters
Returns
- bool
True if the two ObjectIds are equal.
operator >(ObjectId, ObjectId)
Compares two ObjectIds.
public static bool operator >(ObjectId lhs, ObjectId rhs)
Parameters
Returns
- bool
True if the first ObjectId is greather than the second ObjectId.
operator >=(ObjectId, ObjectId)
Compares two ObjectIds.
public static bool operator >=(ObjectId lhs, ObjectId rhs)
Parameters
Returns
- bool
True if the first ObjectId is greather than or equal to the second ObjectId.
operator !=(ObjectId, ObjectId)
Compares two ObjectIds.
public static bool operator !=(ObjectId lhs, ObjectId rhs)
Parameters
Returns
- bool
True if the two ObjectIds are not equal.
operator <(ObjectId, ObjectId)
Compares two ObjectIds.
public static bool operator <(ObjectId lhs, ObjectId rhs)
Parameters
Returns
- bool
True if the first ObjectId is less than the second ObjectId.
operator <=(ObjectId, ObjectId)
Compares two ObjectIds.
public static bool operator <=(ObjectId lhs, ObjectId rhs)
Parameters
Returns
- bool
True if the first ObjectId is less than or equal to the second ObjectId.