Table of Contents

Class EnumReflectionHelpers

Namespace
Garyon.Reflection
Assembly
Garyon.dll

Provides reflection helpers for enum types.

public static class EnumReflectionHelpers
Inheritance
EnumReflectionHelpers
Inherited Members

Methods

GetEnumFieldDescriptionDictionary<T>()

Constructs a Dictionary<TKey, TValue> mapping the provided enum's fields to their descriptions, as provided through their DescriptionAttributes.

public static Dictionary<T, string> GetEnumFieldDescriptionDictionary<T>() where T : struct, Enum

Returns

Dictionary<T, string>

The resulting constructed Dictionary<TKey, TValue> containing the enum fields mapped to their descriptions.

Type Parameters

T

The type of the enum whose fields to construct the dictionary of.

GetEnumFieldDictionary<TEnum, TAttribute>()

Constructs a Dictionary<TKey, TValue> mapping the provided enum's fields to a sought attribute.

public static Dictionary<TEnum, TAttribute> GetEnumFieldDictionary<TEnum, TAttribute>() where TEnum : struct, Enum where TAttribute : Attribute

Returns

Dictionary<TEnum, TAttribute>

The resulting constructed Dictionary<TKey, TValue> containing the enum fields mapped to their chosen sought attributes.

Type Parameters

TEnum

The type of the enum whose fields to construct the dictionary of.

TAttribute

The type of the attribute to seek for in each field.

GetEnumFieldDictionary<TEnum, TAttribute, TMappedValue>(Func<TAttribute?, TMappedValue?>)

Constructs a Dictionary<TKey, TValue> mapping the provided enum's fields to a value provided from a sought attribute.

public static Dictionary<TEnum, TMappedValue> GetEnumFieldDictionary<TEnum, TAttribute, TMappedValue>(Func<TAttribute?, TMappedValue?> selector) where TEnum : struct, Enum where TAttribute : Attribute

Parameters

selector Func<TAttribute, TMappedValue>

The function that selects the value to map the respective field to, given its attribute instance, if found. It should expect nulls.

Returns

Dictionary<TEnum, TMappedValue>

The resulting constructed Dictionary<TKey, TValue> containing the enum fields mapped to their chosen values.

Type Parameters

TEnum

The type of the enum whose fields to construct the dictionary of.

TAttribute

The type of the attribute to seek for in each field.

TMappedValue

The type of the value to map the fields to.

GetEnumFields<T>()

Gets all the publicly available constant enum fields.

public static FieldInfo[] GetEnumFields<T>() where T : struct, Enum

Returns

FieldInfo[]

An array containing the enum fields of the provided type.

Type Parameters

T

The type of the enum whose enum fields to get.