コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }