Class Enumeration<T, TValue>
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Represents a generic (name, value) tuple that can be used to construct more complex Enum-like objects.
public abstract class Enumeration<T, TValue> : IEquatable<T>, IComparable<T>, IComparable where T : Enumeration<T, TValue> where TValue : notnullType Parameters
- T
- Enumeration type. Use the "Curiously Recurring Template Pattern" (CRTP) approach. 
- TValue
- Value type. 
- Inheritance
- 
      
      Enumeration<T, TValue>
- Implements
- 
      IEquatable<T>IComparable<T>
- Inherited Members
- Extension Methods
Constructors
Enumeration(string, TValue)
Creates a new Enumeration<T, TValue> instance.
protected Enumeration(string name, TValue value)Parameters
- namestring
- Entry's name. 
- valueTValue
- Entry's value. 
Properties
Name
Enumeration entry's name.
public string Name { get; }Property Value
Value
Enumeration entry's value.
public TValue Value { get; }Property Value
- TValue
Methods
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
- objobject
- 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 - objin the sort order.- Zero - This instance occurs in the same position in the sort order as - obj.- Greater than zero - This instance follows - objin the sort order.
Exceptions
- ArgumentException
- objis not the same type as this instance.
CompareTo(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(T? other)Parameters
- otherT
- 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 - otherin the sort order.- Zero - This instance occurs in the same position in the sort order as - other.- Greater than zero - This instance follows - otherin the sort order.
Equals(object?)
Determines whether the specified object is equal to the current object.
[Pure]
public override sealed bool Equals(object? obj)Parameters
- objobject
- The object to compare with the current object. 
Returns
Equals(T?)
Indicates whether the current object is equal to another object of the same type.
[Pure]
public bool Equals(T? other)Parameters
- otherT
- An object to compare with this object. 
Returns
GetAllMembers()
Extracts all valid public and static enumeration members (limited to auto-properties and members)
of T type from that type.
[Pure]
protected static IEnumerable<T> GetAllMembers()Returns
- IEnumerable<T>
- Collection of valid members of - Ttype from that type.
GetHashCode()
Serves as the default hash function.
[Pure]
public override sealed int GetHashCode()Returns
- int
- A hash code for the current object. 
GetNameDictionary()
Extracts all valid public and static enumeration members (limited to auto-properties and members)
of T type from that type and creates a dictionary out of them where entries are identified by
their underlying Name.
[Pure]
protected static Dictionary<string, T> GetNameDictionary()Returns
- Dictionary<string, T>
- New Dictionary<TKey, TValue> instance. 
Exceptions
- ArgumentException
- When underlying enumeration names are duplicated. 
GetValueDictionary()
Extracts all valid public and static enumeration members (limited to auto-properties and members)
of T type from that type and creates a dictionary out of them where entries are identified by
their underlying Value.
[Pure]
protected static Dictionary<TValue, T> GetValueDictionary()Returns
- Dictionary<TValue, T>
- New Dictionary<TKey, TValue> instance. 
Exceptions
- ArgumentException
- When underlying enumeration values are duplicated. 
ToString()
Returns a string representation of this Enumeration<T, TValue> instance.
[Pure]
public override string ToString()Returns
- string
- String representation. 
Operators
operator ==(Enumeration<T, TValue>?, Enumeration<T, TValue>?)
Checks if a is equal to b.
[Pure]
public static bool operator ==(Enumeration<T, TValue>? a, Enumeration<T, TValue>? b)Parameters
- aEnumeration<T, TValue>
- First operand. 
- bEnumeration<T, TValue>
- Second operand. 
Returns
- bool
- true when operands are equal, otherwise false. 
operator >(Enumeration<T, TValue>?, Enumeration<T, TValue>?)
Checks if a is greater than b.
[Pure]
public static bool operator >(Enumeration<T, TValue>? a, Enumeration<T, TValue>? b)Parameters
- aEnumeration<T, TValue>
- First operand. 
- bEnumeration<T, TValue>
- Second operand. 
Returns
- bool
- true when - ais greater than- b, otherwise false.
operator >=(Enumeration<T, TValue>?, Enumeration<T, TValue>?)
Checks if a is greater than or equal to b.
[Pure]
public static bool operator >=(Enumeration<T, TValue>? a, Enumeration<T, TValue>? b)Parameters
- aEnumeration<T, TValue>
- First operand. 
- bEnumeration<T, TValue>
- Second operand. 
Returns
- bool
- true when - ais greater than or equal to- b, otherwise false.
implicit operator TValue(Enumeration<T, TValue>)
Converts this instance to the underlying value type. Returns Value of e.
[Pure]
public static implicit operator TValue(Enumeration<T, TValue> e)Parameters
- eEnumeration<T, TValue>
- Enumeration entry. 
Returns
- TValue
- Value of - e.
operator !=(Enumeration<T, TValue>?, Enumeration<T, TValue>?)
Checks if a is not equal to b.
[Pure]
public static bool operator !=(Enumeration<T, TValue>? a, Enumeration<T, TValue>? b)Parameters
- aEnumeration<T, TValue>
- First operand. 
- bEnumeration<T, TValue>
- Second operand. 
Returns
- bool
- true when operands are not equal, otherwise false. 
operator <(Enumeration<T, TValue>?, Enumeration<T, TValue>?)
Checks if a is less than b.
[Pure]
public static bool operator <(Enumeration<T, TValue>? a, Enumeration<T, TValue>? b)Parameters
- aEnumeration<T, TValue>
- First operand. 
- bEnumeration<T, TValue>
- Second operand. 
Returns
- bool
- true when - ais less than- b, otherwise false.
operator <=(Enumeration<T, TValue>?, Enumeration<T, TValue>?)
Checks if a is less than or equal to b.
[Pure]
public static bool operator <=(Enumeration<T, TValue>? a, Enumeration<T, TValue>? b)Parameters
- aEnumeration<T, TValue>
- First operand. 
- bEnumeration<T, TValue>
- Second operand. 
Returns
- bool
- true when - ais less than or equal to- b, otherwise false.