using System; using System.Linq; using System.Runtime.Serialization; namespace AMWD.Net.Api.Cloudflare { /// /// Extension methods for s. /// public static class EnumExtensions { /// /// Gets the of the when available, otherwise the . /// /// The enum value. public static string? GetEnumMemberValue(this Enum value) { var fieldInfo = value.GetType().GetField(value.ToString()); if (fieldInfo == null) return value.ToString(); var enumMember = fieldInfo .GetCustomAttributes(typeof(EnumMemberAttribute), inherit: false) .Cast() .FirstOrDefault(); if (enumMember == null) return value.ToString(); return enumMember.Value; } } }