/// <summary> /// Throws an exception if there are any enum values that are invalid. <paramref name="this" /> is expected to be non-null. /// </summary> /// <param name="this">The sequence to check. Expected to be non-null.</param> /// <param name="name">The name of the parameter.</param> /// <exception cref="ArgumentException"><paramref name="this" /> contains any invalid enum values.</exception> public static void ThrowIfAnyInvalidEnums <TValue>(this IEnumerable <TValue> @this, string name = null) where TValue : struct, IComparable { EnumExt <TValue> .CheckType(); if (@this.Any(v => !EnumExt <TValue> .IsValidValue(v))) { throw new ArgumentException("Must not have any invalid enum values", name); } }
/// <summary> /// Determines whether an enum value contains an invalid value. /// For a non-<see cref="System.FlagsAttribute"/> enum, an invalid value is one that is not explicitly defined. /// For a <see cref="System.FlagsAttribute"/> enum, an invalid value is one in which there is no way to express the value in terms of the flags. /// </summary> /// <param name="value">The value to test.</param> /// <returns>true if the enum value is consistent with the enum's definition, false otherwise.</returns> public static bool IsValidValue <TValue>(TValue value) where TValue : struct, IComparable { return(EnumExt <TValue> .IsValidValue(value)); }