using System;
using System.Collections.Generic;
using System.Linq;
using Humanizer;
namespace Artemis.UI.Shared
{
///
/// Provides utilities for display enums in a human readable form
///
public static class EnumUtilities
{
///
/// Creates a list containing a for each value in the enum type
///
/// The enum type to create value descriptions for
/// A list containing a for each value in the enum type
public static IEnumerable GetAllValuesAndDescriptions(Type t)
{
if (!t.IsEnum)
throw new ArgumentException($"{nameof(t)} must be an enum type");
return Enum.GetValues(t).Cast().Select(e => new ValueDescription {Value = e, Description = e.Humanize()}).ToList();
}
///
/// Humanizes the given enum value using the Humanizer library
///
/// The enum value to humanize
/// A humanized string describing the given value
public static string HumanizeValue(Enum value)
{
return value.Humanize();
}
}
public class ValueDescription
{
public object Value { get; set; }
public string Description { get; set; }
}
}