Class UnmanagedEnumClass<TSource, TObject>
A class which allows unmanaged data implicit conversions.
Can be used along with unmanaged, means it doesn't require another UnmanagedEnumClass<TSource, TObject> instance to be comparable or usable.
public abstract class UnmanagedEnumClass<TSource, TObject> : IComparable, IEquatable<TObject>, IComparable<TObject>, IComparer<TObject> where TSource : unmanaged, IComparable, IFormattable, IConvertible, IComparable<TSource>, IEquatable<TSource> where TObject : UnmanagedEnumClass<TSource, TObject>
Type Parameters
TSourceThe type of the unmanaged source object to handle the instance of.
TObjectThe type of the child object to handle the instance of.
- Inheritance
-
UnmanagedEnumClass<TSource, TObject>
- Implements
-
IEquatable<TObject>IComparable<TObject>IComparer<TObject>
- Inherited Members
- Extension Methods
Constructors
UnmanagedEnumClass(TSource)
Initializes a new instance of the UnmanagedEnumClass<TSource, TObject> class.
protected UnmanagedEnumClass(TSource value)
Parameters
valueTSourceThe value of the unmanaged 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
valueTSourceThe enum value to be cast.
Returns
- TObject
The cast object.
Cast<T>(IEnumerable<TSource>)
Casts the specified values to the corresponding type.
public static IEnumerable<T> Cast<T>(IEnumerable<TSource> values) where T : TObject
Parameters
valuesIEnumerable<TSource>The enum values to be cast.
Returns
- IEnumerable<T>
The cast
Tobject.
Type Parameters
TThe type to cast the enum to.
Cast<T>(TSource)
Casts the specified value to the corresponding type.
public static T Cast<T>(TSource value) where T : TObject
Parameters
valueTSourceThe enum value to be cast.
Returns
- T
The cast
Tobject.
Type Parameters
TThe type to cast the enum to.
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
xTObjectAn object to compare.
yTObjectAnother 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
objobjectAn 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
otherTObjectAn 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
objobjectThe object to compare.
Returns
Equals(TObject)
Determines whether the specified object is equal to the current object.
public bool Equals(TObject other)
Parameters
otherTObjectThe 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 UnmanagedEnumClass<TSource, TObject>.
public static TSource[] GetValues(Type type)
Parameters
typeTypeThe UnmanagedEnumClass<TSource, TObject> type.
Returns
- TSource[]
An array of the values of the constants in a specified UnmanagedEnumClass<TSource, TObject>.
Parse(string)
Parses a string object.
public static TObject Parse(string obj)
Parameters
objstringThe 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
valueTSourceThe enum value to be cast.
resultTObjectThe cast
value.
Returns
ToString()
Converts the UnmanagedEnumClass<TSource, TObject> instance to a human-readable string representation.
public override string ToString()
Returns
- string
A human-readable string representation of the UnmanagedEnumClass<TSource, TObject> instance.
Operators
implicit operator TSource(UnmanagedEnumClass<TSource, TObject>)
Implicitly converts the UnmanagedEnumClass<TSource, TObject> to TSource.
public static implicit operator TSource(UnmanagedEnumClass<TSource, TObject> value)
Parameters
valueUnmanagedEnumClass<TSource, TObject>The value to convert.
Returns
- TSource
implicit operator TObject(UnmanagedEnumClass<TSource, TObject>)
Implicitly converts the UnmanagedEnumClass<TSource, TObject> to TObject.
public static implicit operator TObject(UnmanagedEnumClass<TSource, TObject> value)
Parameters
valueUnmanagedEnumClass<TSource, TObject>The value to convert.
Returns
- TObject
implicit operator UnmanagedEnumClass<TSource, TObject>(TSource)
Implicitly converts the TSource to EnumClass<TSource, TObject>.
public static implicit operator UnmanagedEnumClass<TSource, TObject>(TSource value)
Parameters
valueTSourceThe value to convert.
Returns
- UnmanagedEnumClass<TSource, TObject>