PalacePal/Pal.Common/EnumExtensions.cs

16 lines
465 B
C#
Raw Normal View History

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