Class EnumClass<TSource, TObject>
A class which allows Enum implicit conversions.
Can be used along with Enum, means it doesn't require another EnumClass<TSource, TObject> instance to be comparable or usable.
public abstract class EnumClass<TSource, TObject> : IComparable, IEquatable<TObject>, IComparable<TObject>, IComparer<TObject> where TSource : Enum where TObject : EnumClass<TSource, TObject>Type Parameters
- TSource
- The type of the source object to handle the instance of. 
- TObject
- The type of the child object to handle the instance of. 
- Inheritance
- 
      
      EnumClass<TSource, TObject>
- Implements
- 
      
      IEquatable<TObject>IComparable<TObject>IComparer<TObject>
- Inherited Members
- Extension Methods
Constructors
EnumClass(TSource)
Initializes a new instance of the EnumClass<TSource, TObject> class.
protected EnumClass(TSource value)Parameters
- valueTSource
- The value of the enum item. 
Properties
Name
Gets the name determined from reflection.
public string Name { get; }Property Value
Value
Gets the value of the enum item.
public TSource Value { get; }Property Value
- TSource
Values
Gets all TObject object instances.
public static IEnumerable<TObject> Values { get; }Property Value
- IEnumerable<TObject>
Methods
Cast(IEnumerable<TSource>)
Casts the specified values to the corresponding type.
public static IEnumerable<TObject> Cast(IEnumerable<TSource> values)Parameters
- valuesIEnumerable<TSource>
- The enum values to be cast. 
Returns
- IEnumerable<TObject>
- The cast object. 
Cast(TSource)
Casts the specified value to the corresponding type.
public static TObject Cast(TSource value)Parameters
- valueTSource
- The enum value to be cast. 
Returns
- TObject
- The cast object. 
Compare(TObject, TObject)
Compares the specified object 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.
public int Compare(TObject x, TObject y)Parameters
- xTObject
- An object to compare. 
- yTObject
- Another object to compare. 
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.
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 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(TObject)
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.
public int CompareTo(TObject other)Parameters
- otherTObject
- 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.
public override bool Equals(object obj)Parameters
- objobject
- The object to compare. 
Returns
Equals(TObject)
Determines whether the specified object is equal to the current object.
public bool Equals(TObject other)Parameters
- otherTObject
- The object to compare. 
Returns
GetHashCode()
Returns a the 32-bit signed hash code of the current object instance.
public override int GetHashCode()Returns
- int
- The 32-bit signed hash code of the current object instance. 
GetValues(Type)
Retrieves an array of the values of the constants in a specified EnumClass<TSource, TObject>.
public static TSource[] GetValues(Type type)Parameters
- typeType
- The EnumClass<TSource, TObject> type. 
Returns
- TSource[]
- An array of the values of the constants in a specified EnumClass<TSource, TObject>. 
Parse(string)
Parses a string object.
public static TObject Parse(string obj)Parameters
- objstring
- The object to be parsed. 
Returns
- TObject
- The corresponding - TObjectobject instance, or null if not found.
SafeCast(IEnumerable<TSource>, out IEnumerable<TObject>)
Safely casts the specified values to the corresponding type.
public static bool SafeCast(IEnumerable<TSource> values, out IEnumerable<TObject> results)Parameters
- valuesIEnumerable<TSource>
- The enum value to be cast. 
- resultsIEnumerable<TObject>
- The cast - values.
Returns
SafeCast(TSource, out TObject)
Safely casts the specified value to the corresponding type.
public static bool SafeCast(TSource value, out TObject result)Parameters
- valueTSource
- The enum value to be cast. 
- resultTObject
- The cast - value.
Returns
ToString()
Converts the EnumClass<TSource, TObject> instance to a human-readable string representation.
public override string ToString()Returns
- string
- A human-readable string representation of the EnumClass<TSource, TObject> instance. 
Operators
implicit operator TSource(EnumClass<TSource, TObject>)
Implicitly converts the EnumClass<TSource, TObject> to TSource.
public static implicit operator TSource(EnumClass<TSource, TObject> value)Parameters
- valueEnumClass<TSource, TObject>
- The value to convert. 
Returns
- TSource
implicit operator TObject(EnumClass<TSource, TObject>)
Implicitly converts the EnumClass<TSource, TObject> to TObject.
public static implicit operator TObject(EnumClass<TSource, TObject> value)Parameters
- valueEnumClass<TSource, TObject>
- The value to convert. 
Returns
- TObject
implicit operator EnumClass<TSource, TObject>(TSource)
Implicitly converts the TSource to EnumClass<TSource, TObject>.
public static implicit operator EnumClass<TSource, TObject>(TSource value)Parameters
- valueTSource
- The value to convert. 
Returns
- EnumClass<TSource, TObject>