//[NotNull, Pure]
        //private static DesignByContractViolationException CreateEnumException<T>([NotNull] object value, [CanBeNull] string name = null)
        //{
        //    string enumType = typeof(T).Name;
        //    string enumValue = value.ToString();
        //    name = name ?? "enum";
        //    return new DesignByContractViolationException($"Unsupported {name} value: {enumValue} ({enumType})");
        //}

        /// <summary>
        ///     Checks whether specified value can be used as (cast to) an enum value.
        /// </summary>
        /// <typeparam name="T">Type of enum to check</typeparam>
        /// <param name="value">Value of enum to check</param>
        public static void IfEnumNotDefined <T>([NotNull][System.Diagnostics.CodeAnalysis.NotNull] object value)
        {
            if (Enum.IsDefined(typeof(T), value) == false)
            {
                throw Fail.Because(Violation.WhenEnumOutOfRange <T>(null, value));
            }
        }
 /// <summary>
 /// Checks whether specified enum value is defined.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 public static void IfEnumNotDefined <T>(T value) where T : struct
 {
     // ReSharper disable once HeapView.BoxingAllocation
     if (Enum.IsDefined(typeof(T), value) == false)
     {
         throw Fail.Because(Violation.WhenEnumOutOfRange <T>(null, value));
     }
 }
        public static T CastEnumOrFail <T>([CanBeNull][NoEnumeration] this Enum value, [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            Type type = value.GetType();

            if (Enum.IsDefined(type, value) == false)
            {
                throw Fail.Because(Violation.WhenEnumOutOfRange <T>(name, value));
            }

            return(value.CastOrFail <T>(name));
        }
 public static DesignByContractViolationException BecauseEnumOutOfRange <T>(T value)
     where T : struct
 {
     // ReSharper disable once HeapView.BoxingAllocation
     return(Fail.Because(Violation.WhenEnumOutOfRange <T>(null, value)));
 }