using System;
using System.Collections.Generic;
namespace MPF.Frontend.ComboBoxItems
{
///
/// A generic combo box element
///
/// Enum type representing the possible values
public class Element : IEquatable>, 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 => EnumExtensions.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 List> GenerateElements()
{
var enumArr = (T[])Enum.GetValues(typeof(T));
return [.. Array.ConvertAll(enumArr, e => new Element(e))];
}
///
public override bool Equals(object? obj)
{
return Equals(obj as Element);
}
///
public bool Equals(Element? other)
{
if (other == null)
return false;
return Name == other.Name;
}
///
public override int GetHashCode() => base.GetHashCode();
}
}