using System; using static PKHeX.Core.InstructionComparer; namespace PKHeX.Core; /// /// Value comparison type /// public enum InstructionComparer : byte { None, IsEqual, IsNotEqual, IsGreaterThan, IsGreaterThanOrEqual, IsLessThan, IsLessThanOrEqual, } /// /// Extension methods for /// public static class InstructionComparerExtensions { extension(InstructionComparer comparer) { /// /// Indicates if the is supported by the logic. /// /// True if supported, false if unsupported. public bool IsSupported => comparer switch { IsEqual => true, IsNotEqual => true, IsGreaterThan => true, IsGreaterThanOrEqual => true, IsLessThan => true, IsLessThanOrEqual => true, _ => false, }; /// /// Checks if the compare operator is satisfied by a boolean comparison result. /// /// Result from Equals comparison /// True if satisfied /// Only use this method if the comparison is boolean only. Use the otherwise. public bool IsCompareEquivalence(bool compareResult) => comparer switch { IsEqual => compareResult, IsNotEqual => !compareResult, _ => false, }; /// /// Checks if the compare operator is satisfied by the result. /// /// Result from CompareTo /// True if satisfied public bool IsCompareOperator(int compareResult) => comparer switch { IsEqual => compareResult is 0, IsNotEqual => compareResult is not 0, IsGreaterThan => compareResult > 0, IsGreaterThanOrEqual => compareResult >= 0, IsLessThan => compareResult < 0, IsLessThanOrEqual => compareResult <= 0, _ => false, }; } }