Created
April 14, 2023 15:39
-
-
Save smdooley/288adb404a7abde0f1dc11b3b55c0b40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel; | |
using System.Linq; | |
using System.Reflection; | |
namespace Project.Core.Extensions | |
{ | |
public static class EnumExtensions | |
{ | |
public static string GetEnumDescription(this Enum value) | |
{ | |
FieldInfo fi = value.GetType().GetField(value.ToString()); | |
DescriptionAttribute[] attributes = fi.GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[]; | |
if (attributes != null && attributes.Any()) | |
{ | |
return attributes.First().Description; | |
} | |
return value.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment