using System;
using System.Collections.Generic;
using System.Linq;
using MPF.Core.Converters;
namespace MPF.UI.Core.ComboBoxItems
{
///
/// A generic combo box element
///
/// Enum type representing the possible values
public class Element : IElement where T : struct, Enum
{
private readonly T Data;
public Element(T data) => Data = data;
///
/// Allow elements to be used as their internal enum type
///
///
public static implicit operator T? (Element item) => item?.Data;
///
public string Name => EnumConverter.GetLongName(Data);
public override string ToString() => Name;
///
/// Internal enum value
///
public T Value => Data;
///
/// Determine if the item is selected or not
///
/// Only applies to CheckBox type
public bool IsChecked { get; set; }
///
/// Generate all elements associated with the data enum type
///
///
public static IEnumerable> GenerateElements()
{
return Enum.GetValues(typeof(T))
.OfType()
.Select(e => new Element(e));
}
}
}