/// <summary> /// Tries to get the range that contains the next-lower value /// from this <paramref name="value"/>. /// </summary> /// <param name="value">This value to locate.</param> /// <param name="nextLowerValue">The range containing the next-lower enum value.</param> /// <returns>True if found.</returns> public bool TryGetNextLowerValue(T value, out EnumValueRange <T> nextLowerValue) { int index = ranges.BinarySearchIndexOf(Predicate); Debug.Assert(index >= 0, "index >= 0"); if (index > 0) { nextLowerValue = ranges[index - 1]; return(true); } nextLowerValue = null; return(false); int Predicate(EnumValueRange <T> member) => member.CompareTo(value); }
static double DoubleSelector(EnumValueRange <T> item) => item.DoubleValue;
/// <summary> /// Please notice: this is a convenience method that tries to fetch /// the next-lower defined Enum value from this given /// <paramref name="value"/>. This method first gets the /// <see cref="EnumValueRange{T}.Set"/> for <typeparamref name="T"/> /// --- which is a sorted set of ranges for /// all defined values --- and then searches for the next-lower /// value. This guarantees that all duplicate values are /// sorted; and the returned range includes any duplicate values. /// Since the method contructs and sorts the list, it is not /// guaranteed to be performance-critical /// </summary> /// <typeparam name="T">The Enum type.</typeparam> /// <param name="value">This value to locate.</param> /// <param name="nextHigherValue">The range containing the next-lower enum value.</param> /// <returns>True if found.</returns> public static bool TryGetNextLowerValue <T>(this T value, out EnumValueRange <T> nextLowerValue) where T : struct, Enum => EnumValueRange <T> .Get() .TryGetNextLowerValue(value, out nextLowerValue);
/// <summary> /// Convenience method returns <see cref="EnumValueRange{T}.Get"/> /// for <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The Enum type.</typeparam> /// <returns>Not null.</returns> public static EnumValueRange <T> .Set GetValueRanges <T>() where T : struct, Enum => EnumValueRange <T> .Get();