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
Properties
Id
Gets the identifier of the value, used for equality and ordering.
public long Id { get; }
Property Value
Name
Gets the display name of the value.
public string Name { get; }
Property Value
Methods
CompareTo(Enumeration)
Compares this value with another value by Id.
public int CompareTo(Enumeration other)
Parameters
otherEnumerationThe 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 followsotherorotheris null.
Equals(Enumeration)
Determines whether the specified value has the same Id as this value.
public virtual bool Equals(Enumeration other)
Parameters
otherEnumerationThe value to compare with this value.
Returns
Equals(object)
Determines whether the specified object is an Enumeration with the same Id.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with this value.
Returns
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
TThe enumeration type. Every public static field declared on it must be of type
T.
Exceptions
- InvalidCastException
A public static field declared on
Tis not of typeT(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
Operators
operator ==(Enumeration, Enumeration)
Determines whether two values are equal.
public static bool operator ==(Enumeration left, Enumeration right)
Parameters
leftEnumerationThe first value to compare.
rightEnumerationThe second value to compare.
Returns
operator >(Enumeration, Enumeration)
Determines whether left follows right. null precedes any value.
public static bool operator >(Enumeration left, Enumeration right)
Parameters
leftEnumerationThe first value to compare.
rightEnumerationThe second value to compare.
Returns
operator >=(Enumeration, Enumeration)
Determines whether left follows or equals right. null precedes any value.
public static bool operator >=(Enumeration left, Enumeration right)
Parameters
leftEnumerationThe first value to compare.
rightEnumerationThe second value to compare.
Returns
operator !=(Enumeration, Enumeration)
Determines whether two values are not equal.
public static bool operator !=(Enumeration left, Enumeration right)
Parameters
leftEnumerationThe first value to compare.
rightEnumerationThe second value to compare.
Returns
operator <(Enumeration, Enumeration)
Determines whether left precedes right. null precedes any value.
public static bool operator <(Enumeration left, Enumeration right)
Parameters
leftEnumerationThe first value to compare.
rightEnumerationThe second value to compare.
Returns
operator <=(Enumeration, Enumeration)
Determines whether left precedes or equals right. null precedes any value.
public static bool operator <=(Enumeration left, Enumeration right)
Parameters
leftEnumerationThe first value to compare.
rightEnumerationThe second value to compare.