Click or drag to resize

EnumExGetDisplayNamesTEnum Method

Returns the DisplayName of an enum type.

Namespace:  System
Assembly:  Cauldron.Activator (in Cauldron.Activator.dll) Version: 3.2.0.1 (3.2.0.1)
Syntax
C#
public static IReadOnlyDictionary<TEnum, string> GetDisplayNames<TEnum>()
where TEnum : struct, new(), IConvertible

Type Parameters

TEnum
The enum type

Return Value

Type: IReadOnlyDictionaryTEnum, String
A dictionary of display names with the enum value member as key
Examples
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);
    }
}
See Also