hallo
This commit is contained in:
15
Desktop/hallo/LEA/Extensions/EnumExtensions.cs
Normal file
15
Desktop/hallo/LEA/Extensions/EnumExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
|
||||
namespace LEA.Extensions;
|
||||
|
||||
public static class EnumExtensions
|
||||
{
|
||||
public static string GetDisplayName(this Enum value)
|
||||
{
|
||||
var memberInfo = value.GetType().GetMember(value.ToString()).FirstOrDefault();
|
||||
var displayAttribute = memberInfo?.GetCustomAttribute<DisplayAttribute>();
|
||||
return displayAttribute?.GetName() ?? value.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user