Table of Contents

Struct Identifier

Namespace
LfrlAnvil.Identifiers
Assembly
LfrlAnvil.Identifiers.dll

A lightweight object that can be used as a unique ID.

public readonly struct Identifier : IEquatable<Identifier>, IComparable<Identifier>, IComparable
Implements
Inherited Members

Constructors

Identifier(ulong)

Creates a new Identifier instance.

public Identifier(ulong value)

Parameters

value ulong

Underlying value.

Identifier(ulong, ushort)

Creates a new Identifier instance.

public Identifier(ulong high, ushort low)

Parameters

high ulong

Desired High value. Only the first 48 bits will be used.

low ushort

Desired Low value.

Fields

MaxHighValue

Specifies maximum possible High value.

public const ulong MaxHighValue = 281474976710655

Field Value

ulong

Value

Underlying value.

public readonly ulong Value

Field Value

ulong

Properties

High

Specifies the 48-bit high value of this instance. If this Identifier has been created by an IdentifierGenerator then this value represents a Timestamp at which it has been created. That Timestamp can be extracted by invoking the GetTimestamp(Identifier) method.

public ulong High { get; }

Property Value

ulong

Low

Specifies the low value of this instance. If this Identifier has been created by an IdentifierGenerator then this value represents a unique sequential number with which it has been created at a given time slice represented by its High value.

public ushort Low { get; }

Property Value

ushort

Methods

CompareTo(Identifier)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(Identifier other)

Parameters

other Identifier

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

CompareTo(object?)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(object? obj)

Parameters

obj object

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes obj in the sort order.
Zero This instance occurs in the same position in the sort order as obj.
Greater than zero This instance follows obj in the sort order.

Exceptions

ArgumentException

obj is not the same type as this instance.

Equals(Identifier)

Indicates whether the current object is equal to another object of the same type.

[Pure]
public bool Equals(Identifier other)

Parameters

other Identifier

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

[Pure]
public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

[Pure]
public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns a string representation of this Identifier instance.

[Pure]
public override string ToString()

Returns

string

String representation.

Operators

operator ==(Identifier, Identifier)

Checks if a is equal to b.

[Pure]
public static bool operator ==(Identifier a, Identifier b)

Parameters

a Identifier

First operand.

b Identifier

Second operand.

Returns

bool

true when operands are equal, otherwise false.

explicit operator ulong(Identifier)

Converts the provided id to ulong. Returns Value.

[Pure]
public static explicit operator ulong(Identifier id)

Parameters

id Identifier

Object to convert.

Returns

ulong

Returns Value.

operator >(Identifier, Identifier)

Checks if a is greater than b.

[Pure]
public static bool operator >(Identifier a, Identifier b)

Parameters

a Identifier

First operand.

b Identifier

Second operand.

Returns

bool

true when a is greater than b, otherwise false.

operator >=(Identifier, Identifier)

Checks if a is greater than or equal to b.

[Pure]
public static bool operator >=(Identifier a, Identifier b)

Parameters

a Identifier

First operand.

b Identifier

Second operand.

Returns

bool

true when a is greater than or equal to b, otherwise false.

operator !=(Identifier, Identifier)

Checks if a is not equal to b.

[Pure]
public static bool operator !=(Identifier a, Identifier b)

Parameters

a Identifier

First operand.

b Identifier

Second operand.

Returns

bool

true when operands are not equal, otherwise false.

operator <(Identifier, Identifier)

Checks if a is less than b.

[Pure]
public static bool operator <(Identifier a, Identifier b)

Parameters

a Identifier

First operand.

b Identifier

Second operand.

Returns

bool

true when a is less than b, otherwise false.

operator <=(Identifier, Identifier)

Checks if a is less than or equal to b.

[Pure]
public static bool operator <=(Identifier a, Identifier b)

Parameters

a Identifier

First operand.

b Identifier

Second operand.

Returns

bool

true when a is less than or equal to b, otherwise false.