Class EnumExtensions
Contains extensions for the Enum class.
Inherited Members
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class EnumExtensions
Methods
| Edit this page View SourceByteConversionMethod(in Type)
Gets a MethodInfo for a method that allows performing the conversion of the enumeration type to a byte array.
Declaration
public static MethodInfo ByteConversionMethod(in Type enumType)
Parameters
Type | Name | Description |
---|---|---|
Type | enumType | Type of the enumeration to convert. |
Returns
Type | Description |
---|---|
MethodInfo | A MethodInfo for a method that converts from the underlying type of the enumeration to a byte array. |
ByteConversionMethod<T>()
Gets a MethodInfo for a method that allows
performing the conversion of T
to a
byte array.
Declaration
public static MethodInfo ByteConversionMethod<T>() where T : struct, Enum
Returns
Type | Description |
---|---|
MethodInfo | A MethodInfo for a method that converts from the underlying type of the enumeration to a byte array. |
Type Parameters
Name | Description |
---|---|
T | Type of the enumeration to convert. |
GetAttribute<T>(Enum)
Returns the attribute associated with the enumeration value declaration.
Declaration
public static T? GetAttribute<T>(this Enum enumValue) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
Enum | enumValue |
Returns
Type | Description |
---|---|
T | An attribute of the type |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit Attribute. |
GetAttributes<T>(Enum)
Returns the attribute associated with the specified assembly.
Declaration
public static IEnumerable<T>? GetAttributes<T>(this Enum enumValue) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
Enum | enumValue | Enum from which the attribute will be extracted. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An attribute of the type |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit Attribute. |
HasAttrValue<TAttribute, TValue>(Enum, out TValue)
Determines if a member has a defined attribute.
Declaration
public static bool HasAttrValue<TAttribute, TValue>(this Enum enumValue, out TValue value) where TAttribute : Attribute, IValueAttribute<TValue>
Parameters
Type | Name | Description |
---|---|---|
Enum | enumValue | Member from which the attribute will be extracted. |
TValue | value | Output parameter. If an attribute of type
|
Returns
Type | Description |
---|---|
bool |
Type Parameters
Name | Description |
---|---|
TAttribute | Type of attribute to search for. Must inherit from Attribute and from IValueAttribute<T>. |
TValue | Type of value to return. |
HasAttribute<T>(Enum)
Determines if an enumeration value has a defined attribute.
Declaration
public static bool HasAttribute<T>(this Enum enumValue) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
Enum | enumValue | Enumeration value from which the attribute will be extracted. |
Returns
Type | Description |
---|---|
bool | true if the enumeration value has the attribute, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | Type of the attribute to return. Must inherit Attribute. |
HasAttribute<T>(Enum, out T?)
Determines if an enumeration value has a defined attribute.
Declaration
public static bool HasAttribute<T>(this Enum enumValue, out T? attribute) where T : notnull, Attribute
Parameters
Type | Name | Description |
---|---|---|
Enum | enumValue | Enumeration value from which the attribute will be extracted. |
T | attribute | Output parameter. If an attribute of type
|
Returns
Type | Description |
---|---|
bool | true if the enumeration value has the attribute, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | Type of the attribute to return. Must inherit Attribute. |
HasAttributes<T>(Enum, out IEnumerable<T>)
Determines if a member has a defined attribute.
Declaration
public static bool HasAttributes<T>(this Enum enumValue, out IEnumerable<T> attribute) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
Enum | enumValue | Member from which the attribute will be extracted. |
IEnumerable<T> | attribute | Output parameter. If an attribute of type
|
Returns
Type | Description |
---|---|
bool |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit Attribute. |
NameOf(Enum)
Gets a friendly name for an enumeration value.
Declaration
public static string NameOf(this Enum value)
Parameters
Type | Name | Description |
---|---|---|
Enum | value | Enum from which to get the name. |
Returns
Type | Description |
---|---|
string | A friendly name for |
NamedEnums<T>()
Exposes the values of an Enum as a collection of NamedObject<T>.
Declaration
public static IEnumerable<NamedObject<T>> NamedEnums<T>() where T : struct, Enum
Returns
Type | Description |
---|---|
IEnumerable<NamedObject<T>> | An enumerator that exposes the values of the Enum as a collection of NamedObject<T>. |
Type Parameters
Name | Description |
---|---|
T | Type of the enumeration to get. |
ToBytes(Enum)
Converts an enumeration value to its byte representation.
Declaration
public static byte[] ToBytes(this Enum value)
Parameters
Type | Name | Description |
---|---|---|
Enum | value | Enumeration value to convert. |
Returns
Type | Description |
---|---|
byte[] | A byte array with the representation of the enumeration value. |
Exceptions
Type | Condition |
---|---|
PlatformNotSupportedException | Thrown if the platform is not supported, and the Enum uses an unusual underlying type for which it is not possible to obtain a byte converter. |
ToBytes<T>()
Creates a delegate that converts an enumeration value of the specified type into a byte array.
Declaration
public static Func<T, byte[]> ToBytes<T>() where T : struct, Enum
Returns
Type | Description |
---|---|
Func<T, byte[]> | A delegate that converts an enumeration value of the specified type into a byte array. |
Type Parameters
Name | Description |
---|---|
T | Type of the enumeration to convert. |
ToUnderlyingType(Enum)
Converts an enumeration value to its underlying type.
Declaration
public static object ToUnderlyingType(this Enum value)
Parameters
Type | Name | Description |
---|---|---|
Enum | value | Enumeration value to convert. |
Returns
Type | Description |
---|---|
object | A primitive value equal to the enumeration value. |
ToUnderlyingType<T>(T)
Converts an enumeration value to its underlying type.
Declaration
public static object ToUnderlyingType<T>(this T value) where T : struct, Enum
Parameters
Type | Name | Description |
---|---|---|
T | value | Enumeration value to convert. |
Returns
Type | Description |
---|---|
object | A primitive value equal to the enumeration value. |
Type Parameters
Name | Description |
---|---|
T | Type of the enumeration. |