Files
admin/_docs/02_document/modules/common_extensions_enum_extensions.md
T
2026-04-16 06:25:36 +03:00

1.3 KiB

Module: Azaion.Common.Extensions.EnumExtensions

Purpose

Static utility class for extracting DescriptionAttribute values from enum members and retrieving default enum values.

Public Interface

Method Signature Description
GetDescriptions<T> static Dictionary<T, string> GetDescriptions<T>() where T : Enum Returns all enum values mapped to their [Description] text
GetDescription static string GetDescription(this Enum enumValue) Extension: gets the [Description] of a single enum value
GetDefaultValue<TEnum> static TEnum GetDefaultValue<TEnum>() where TEnum : struct Returns the [DefaultValue] attribute's value for an enum type

Internal Logic

  • GetDescriptions<T> iterates all enum values via Enum.GetValues, using a private helper GetEnumAttrib to extract the DescriptionAttribute via reflection. Falls back to .ToString() when no attribute exists.
  • GetEnumAttrib<T, TAttrib> fetches a custom attribute from an enum member's FieldInfo.

Dependencies

  • System.ComponentModel.DescriptionAttribute, System.Reflection (BCL only)

Consumers

  • BusinessException (static constructor calls GetDescriptions<ExceptionEnum>())

Data Models

None.

Configuration

None.

External Integrations

None.

Security

None.

Tests

None.