Skip to content

Commit 09ce194

Browse files
committed
Create EnumExtensions.cs
1 parent 566cd50 commit 09ce194

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Reflection;
3+
4+
namespace Jordnaer.Extensions;
5+
6+
public static class EnumExtensions
7+
{
8+
public static string? ToDisplayName<T>(this T enumValue) where T : Enum =>
9+
enumValue.GetType()
10+
.GetMember(enumValue.ToString())
11+
.First()
12+
.GetCustomAttribute<DisplayAttribute>()?
13+
.Name;
14+
}

0 commit comments

Comments
 (0)