Created
December 9, 2019 23:35
-
-
Save Orbis25/8df59c0ff97763da1b4434fcaf17224f to your computer and use it in GitHub Desktop.
Simple extension in c# for get the displayName atribute in enums
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
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