I am attempting to get a list of the display names of a given enum. If the enum value has a display name, it should be in the list, if it doesn't the default name should be in the list instead. So if I have an enum like:
public enum SourceFromEnum
{
Youtube,
Reddit,
Instagram,
Facebook,
Twitter,
[Display(Name = "News Website")]
NewsSite,
[Display(Name = "Phone or Computer")]
Device,
}
the list my function produces should be identical to:
List<string> enumDisplayNames = new List<string>()
{
"Youtube",
"Reddit",
"Instagram",
"Facebook",
"Twitter",
"News Website",
"Phone or Computer"
};
I have looked at this post, but as far as I can tell the questions are either not providing lists or are overly complicated for what I'm trying to do.
SourceFromEnuminto some function and get out something identical toenumDisplayNamesGetDisplayValue()method (in the accepted answer). You can ignore all the Razor stuff. The other answers provide variations on the same theme, and all generally apply to your scenario.