using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEngine.TestTools; namespace BracerLib.Utility { /// /// An object-oriented, extensible base class to represent an enum type. /// [ExcludeFromCoverage] public abstract class Enumeration : IComparable { public static IEnumerable GetAll() where T : Enumeration => typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) .Select(f => f.GetValue(null)) .Cast(); public string Name { get; private set; } public int Id { get; private set; } protected Enumeration(int id, string name) => (Id, Name) = (id, name); public override string ToString() => Name; public override bool Equals(object obj) { if (obj is not Enumeration otherValue) return false; var typeMatches = GetType() == obj.GetType(); var valueMatches = Id.Equals(otherValue.Id); return typeMatches && valueMatches; } public override int GetHashCode() => HashCode.Combine(Name, Id); public int CompareTo(object obj) => Id.CompareTo(((Enumeration)obj).Id); } }