Table of Contents

Class Enumeration

Namespace
KYS.EFCore.Library
Assembly
KYS.EFCore.Library.dll

Base class for "smart enums": strongly typed enumerations with an Id and a Name, which can carry behaviour, unlike a C# enum.

public class Enumeration : IComparable<Enumeration>, IEquatable<Enumeration>
Inheritance
Enumeration
Implements
Inherited Members

Remarks

Derive from this class and declare each value as a public static readonly field of the derived type. Instances are compared and ordered by Id.

Constructors

Enumeration(long, string)

Initializes a new instance of the Enumeration class.

protected Enumeration(long id, string name)

Parameters

id long

The identifier of the value.

name string

The display name of the value.

Properties

Id

Gets the identifier of the value, used for equality and ordering.

public long Id { get; }

Property Value

long

Name

Gets the display name of the value.

public string Name { get; }

Property Value

string

Methods

CompareTo(Enumeration)

Compares this value with another value by Id.

public int CompareTo(Enumeration other)

Parameters

other Enumeration

The value to compare with this value.

Returns

int

A negative number if this value precedes other, zero if they are equal, or a positive number if this value follows other or other is null.

Equals(Enumeration)

Determines whether the specified value has the same Id as this value.

public virtual bool Equals(Enumeration other)

Parameters

other Enumeration

The value to compare with this value.

Returns

bool

true if the values are equal; otherwise false.

Equals(object)

Determines whether the specified object is an Enumeration with the same Id.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with this value.

Returns

bool

true if the objects are equal; otherwise false.

GetAll<T>()

Returns all values declared as public static fields on T.

public static IEnumerable<T> GetAll<T>() where T : Enumeration

Returns

IEnumerable<T>

The declared values of T.

Type Parameters

T

The enumeration type. Every public static field declared on it must be of type T.

Exceptions

InvalidCastException

A public static field declared on T is not of type T (thrown on enumeration).

GetHashCode()

Returns a hash code based on Id.

public override int GetHashCode()

Returns

int

A hash code for the current value.

ToString()

Returns the Name of the value.

public override string ToString()

Returns

string

The Name of the value.

Operators

operator ==(Enumeration, Enumeration)

Determines whether two values are equal.

public static bool operator ==(Enumeration left, Enumeration right)

Parameters

left Enumeration

The first value to compare.

right Enumeration

The second value to compare.

Returns

bool

true if both are null or have the same Id; otherwise false.

operator >(Enumeration, Enumeration)

Determines whether left follows right. null precedes any value.

public static bool operator >(Enumeration left, Enumeration right)

Parameters

left Enumeration

The first value to compare.

right Enumeration

The second value to compare.

Returns

bool

true if left follows right; otherwise false.

operator >=(Enumeration, Enumeration)

Determines whether left follows or equals right. null precedes any value.

public static bool operator >=(Enumeration left, Enumeration right)

Parameters

left Enumeration

The first value to compare.

right Enumeration

The second value to compare.

Returns

bool

true if left follows or equals right; otherwise false.

operator !=(Enumeration, Enumeration)

Determines whether two values are not equal.

public static bool operator !=(Enumeration left, Enumeration right)

Parameters

left Enumeration

The first value to compare.

right Enumeration

The second value to compare.

Returns

bool

true if the values are not equal; otherwise false.

operator <(Enumeration, Enumeration)

Determines whether left precedes right. null precedes any value.

public static bool operator <(Enumeration left, Enumeration right)

Parameters

left Enumeration

The first value to compare.

right Enumeration

The second value to compare.

Returns

bool

true if left precedes right; otherwise false.

operator <=(Enumeration, Enumeration)

Determines whether left precedes or equals right. null precedes any value.

public static bool operator <=(Enumeration left, Enumeration right)

Parameters

left Enumeration

The first value to compare.

right Enumeration

The second value to compare.

Returns

bool

true if left precedes or equals right; otherwise false.