mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Humanizer;
|
|
|
|
namespace Artemis.Core
|
|
{
|
|
/// <summary>
|
|
/// Provides utilities for display enums in a human readable form
|
|
/// </summary>
|
|
public static class EnumUtilities
|
|
{
|
|
/// <summary>
|
|
/// Creates a list containing a tuple for each value in the enum type
|
|
/// </summary>
|
|
/// <param name="t">The enum type to create value descriptions for</param>
|
|
/// <returns>A list containing a value-description tuple for each value in the enum type</returns>
|
|
public static List<(T, string)> GetAllValuesAndDescriptions<T>() where T : struct, Enum
|
|
{
|
|
return Enum.GetValues<T>().Select(e => (e, e.Humanize())).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a list containing a tuple for each value in the enum type
|
|
/// </summary>
|
|
/// <param name="t">The enum type to create value descriptions for</param>
|
|
/// <returns>A list containing a value-description tuple for each value in the enum type</returns>
|
|
public static List<(Enum, string)> GetAllValuesAndDescriptions(Type t)
|
|
{
|
|
if (!t.IsEnum)
|
|
throw new ArgumentException($"{t} must be an enum type");
|
|
|
|
return Enum.GetValues(t).Cast<Enum>().Select(e => (e, e.Humanize())).ToList();
|
|
}
|
|
}
|
|
} |