Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

568 B
Raw Blame
using System.ComponentModel;

namespace Kavita.Common.Extensions;

public static class EnumExtensions
{
    public static string ToDescription<TEnum>(this TEnum value) where TEnum : struct
    {
        var fi = value.GetType().GetField(value.ToString() ?? string.Empty);

        if (fi == null)
        {
            return value.ToString();
        }

        var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

        return attributes is {Length: > 0} ? attributes[0].Description : value.ToString();
    }
}