Show / Hide Table of Contents

Class EnumExtensions

Contains extensions for the Enum class.

Inheritance
object
EnumExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class EnumExtensions

Methods

| Edit this page View Source

ByteConversionMethod(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.

| Edit this page View Source

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.

| Edit this page View Source

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 T with the associated data in the enumeration value declaration.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

| Edit this page View Source

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 T with the associated data in the declaration of the assembly; or null if the specified attribute is not found.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

| Edit this page View Source

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 TAttribute has been found, the value of the same is returned. It will return default if the member does not have the specified attribute.

Returns
Type Description
bool

true if the member has the attribute, false otherwise.

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.

| Edit this page View Source

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.

| Edit this page View Source

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 T has been found, it is returned. It will return null if the member does not have the specified attribute.

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.

| Edit this page View Source

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 T has been found, the same is returned. It will return null if the member does not have the specified attribute.

Returns
Type Description
bool

true if the member has the attribute, false otherwise.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

| Edit this page View Source

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 value, or the compiled name of value if a friendly name has not been defined using the NameAttribute attribute.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX