Skip to content

Instantly share code, notes, and snippets.

@Orbis25
Created December 9, 2019 23:35
Show Gist options
  • Save Orbis25/8df59c0ff97763da1b4434fcaf17224f to your computer and use it in GitHub Desktop.
Save Orbis25/8df59c0ff97763da1b4434fcaf17224f to your computer and use it in GitHub Desktop.
Simple extension in c# for get the displayName atribute in enums
public static class EnumExtension
{
public static string GetAttribute(this Enum enumValue)
=> enumValue.GetType()?.GetMember(enumValue.ToString())?.FirstOrDefault()?.GetCustomAttribute<DisplayAttribute>(false)?.Name ?? enumValue.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment