Table of Contents

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 : notnull

Type Parameters

T

Enumeration type. Use the "Curiously Recurring Template Pattern" (CRTP) approach.

TValue

Value type.

Inheritance
Enumeration<T, TValue>
Implements
Inherited Members
Extension Methods

Constructors

Enumeration(string, TValue)

Creates a new Enumeration<T, TValue> instance.

protected Enumeration(string name, TValue value)

Parameters

name string

Entry's name.

value TValue

Entry's value.

Properties

Name

Enumeration entry's name.

public string Name { get; }

Property Value

string

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

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.

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

other 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.

Equals(object?)

Determines whether the specified object is equal to the current object.

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

Parameters

obj object

The object to compare with the current object.

Returns

bool

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

Equals(T?)

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

[Pure]
public bool Equals(T? other)

Parameters

other T

An object to compare with this object.

Returns

bool

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

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 T type 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

a Enumeration<T, TValue>

First operand.

b Enumeration<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

a Enumeration<T, TValue>

First operand.

b Enumeration<T, TValue>

Second operand.

Returns

bool

true when a is 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

a Enumeration<T, TValue>

First operand.

b Enumeration<T, TValue>

Second operand.

Returns

bool

true when a is 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

e Enumeration<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

a Enumeration<T, TValue>

First operand.

b Enumeration<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

a Enumeration<T, TValue>

First operand.

b Enumeration<T, TValue>

Second operand.

Returns

bool

true when a is 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

a Enumeration<T, TValue>

First operand.

b Enumeration<T, TValue>

Second operand.

Returns

bool

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