示例#1
0
 /// <summary>
 ///     Checks whether specified value can be used as (casted to) an enum value.
 /// </summary>
 /// <typeparam name="T">Type of enum to check</typeparam>
 /// <param name="value">Value of enum to chceck</param>
 public static void IfEnumNotDefined <T>([NotNull] object value)
 {
     if (Enum.IsDefined(typeof(T), value) == false)
     {
         throw Fail.CreateEnumException <T>(value);
     }
 }
示例#2
0
 /// <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
 {
     if (Enum.IsDefined(typeof(T), value) == false)
     {
         throw Fail.CreateEnumException <T>(value);
     }
 }
示例#3
0
        public static DesignByContractViolationException BecauseEnumOutOfRange <T>(T value)
            where T : struct
        {
            //Fail.RequiresEnumValue(value);

            return(Fail.CreateEnumException <T>(value));
        }
示例#4
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));
        }