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 TEnum : struct, Enum { private readonly TEnum Data; public Element(TEnum data) => Data = data; /// /// Allow elements to be used as their internal enum type /// /// public static implicit operator TEnum?(Element item) => item?.Data; /// public string Name => EnumExtensions.GetLongName(Data); public override string ToString() => Name; /// /// Internal enum value /// public TEnum 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 = (TEnum[])Enum.GetValues(typeof(TEnum)); 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 is null) return false; return Name == other.Name; } /// public override int GetHashCode() => base.GetHashCode(); } }