using Serein.Library.Attributes; using System; using System.Collections.Generic; using System.Reflection; using System.Text; namespace Serein.Library.Utils { public static class EnumHelper { public static TResult GetBoundValue(TEnum enumValue, Func valueSelector) where TEnum : Enum { var fieldInfo = typeof(TEnum).GetField(enumValue.ToString()); var attribute = fieldInfo.GetCustomAttribute(); return attribute != null ? (TResult)valueSelector(attribute) : default; } //public static TResult GetBoundValue(TEnum enumValue, // Func valueSelector) // where TEnum : Enum // where TAttribute : Attribute //{ // var fieldInfo = typeof(TEnum).GetField(enumValue.ToString()); // var attribute = fieldInfo.GetCustomAttribute(); // return attribute != null ? valueSelector(attribute) : default; //} } }