Struct InterlockedEnum<T>
A lightweight representation of an Interlocked (atomic) Enum.
public struct InterlockedEnum<T> : IEquatable<InterlockedEnum<T>>, IComparable<InterlockedEnum<T>>, IComparable where T : struct, Enum
Type Parameters
T
Enum type.
- Implements
- Inherited Members
- Extension Methods
Constructors
InterlockedEnum(T)
Creates a new InterlockedEnum<T> instance.
public InterlockedEnum(T value)
Parameters
value
TInitial value.
Properties
Value
Current value.
public T Value { get; }
Property Value
- T
Methods
CompareExchange(T, T)
Sets Value to the provided value
only if the current Value is equal to the provided comparand
and returns the old value.
public T CompareExchange(T value, T comparand)
Parameters
value
TValue to set.
comparand
TValue used for Value comparison.
Returns
- T
Value before the change.
CompareTo(InterlockedEnum<T>)
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(InterlockedEnum<T> other)
Parameters
other
InterlockedEnum<T>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
objectAn 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(InterlockedEnum<T>)
Indicates whether the current object is equal to another object of the same type.
[Pure]
public bool Equals(InterlockedEnum<T> other)
Parameters
other
InterlockedEnum<T>An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)
Parameters
obj
objectThe 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.
Exchange(T)
Sets Value to the provided value
and returns the old value.
public T Exchange(T value)
Parameters
value
TValue to set.
Returns
- T
Value before the change.
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 InterlockedEnum<T> instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
Write(T)
Sets Value to the provided value
.
public bool Write(T value)
Parameters
value
TValue to set.
Returns
- bool
true when value has changed, otherwise false.
Write(T, T)
public bool Write(T value, T expected)
Parameters
value
TValue to set.
expected
TValue used for Value comparison.
Returns
- bool
true when value has changed, otherwise false.
Operators
operator ==(InterlockedEnum<T>, InterlockedEnum<T>)
Checks if a
is equal to b
.
public static bool operator ==(InterlockedEnum<T> a, InterlockedEnum<T> b)
Parameters
a
InterlockedEnum<T>First operand.
b
InterlockedEnum<T>Second operand.
Returns
- bool
true when operands are equal, otherwise false.
operator >(InterlockedEnum<T>, InterlockedEnum<T>)
Checks if a
is greater than b
.
public static bool operator >(InterlockedEnum<T> a, InterlockedEnum<T> b)
Parameters
a
InterlockedEnum<T>First operand.
b
InterlockedEnum<T>Second operand.
Returns
- bool
true when
a
is greater thanb
, otherwise false.
operator >=(InterlockedEnum<T>, InterlockedEnum<T>)
Checks if a
is greater than or equal to b
.
public static bool operator >=(InterlockedEnum<T> a, InterlockedEnum<T> b)
Parameters
a
InterlockedEnum<T>First operand.
b
InterlockedEnum<T>Second operand.
Returns
- bool
true when
a
is greater than or equal tob
, otherwise false.
operator !=(InterlockedEnum<T>, InterlockedEnum<T>)
Checks if a
is not equal to b
.
public static bool operator !=(InterlockedEnum<T> a, InterlockedEnum<T> b)
Parameters
a
InterlockedEnum<T>First operand.
b
InterlockedEnum<T>Second operand.
Returns
- bool
true when operands are not equal, otherwise false.
operator <(InterlockedEnum<T>, InterlockedEnum<T>)
Checks if a
is less than b
.
public static bool operator <(InterlockedEnum<T> a, InterlockedEnum<T> b)
Parameters
a
InterlockedEnum<T>First operand.
b
InterlockedEnum<T>Second operand.
Returns
- bool
true when
a
is less thanb
, otherwise false.
operator <=(InterlockedEnum<T>, InterlockedEnum<T>)
Checks if a
is less than or equal to b
.
public static bool operator <=(InterlockedEnum<T> a, InterlockedEnum<T> b)
Parameters
a
InterlockedEnum<T>First operand.
b
InterlockedEnum<T>Second operand.
Returns
- bool
true when
a
is less than or equal tob
, otherwise false.