PalacePal/Pal.Common/EnumExtensions.cs

17 lines
507 B
C#
Raw Normal View History

2023-02-12 21:32:22 +00:00
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace Pal.Common
{
public static class EnumExtensions
{
public static int? GetOrder(this Enum e)
{
Type type = e.GetType();
MemberInfo field = type.GetMember(e.ToString()).Single();
DisplayAttribute? attribute = field.GetCustomAttributes(typeof(DisplayAttribute), false).Cast<DisplayAttribute>().FirstOrDefault();
return attribute?.Order;
}
}
}