EnumExGetDisplayNamesTEnum Method |
Namespace: System
public static IReadOnlyDictionary<TEnum, string> GetDisplayNames<TEnum>() where TEnum : struct, new(), IConvertible
using System; using Cauldon.Core; public enum TestEnum { [DisplayName("FIRST")] One, [DisplayName("SECOND")] Two, [DisplayName("THIRD")] Three } public class Program { private static TestEnum GetValue(string value) => MiscUtils .GetDisplayNames<TestEnum>() .FirstOrDefault(x => x.Value == value) .Key; public static Main(string[] args) { var value = GetValue("SECOND"); // Output: Two Console.WriteLine(value); } }