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 T CastEnumOrFail <T>([CanBeNull][NoEnumeration] this Enum value, [NotNull] string name) { Fail.RequiresArgumentName(name); Type type = value.GetType(); if (Enum.IsDefined(type, value) == false) { throw Fail.CreateEnumException <T>(value, name); } return(value.CastOrFail <T>(name)); }