예제 #1
0
        public static TEnum Parse <TEnum>(int value) where TEnum : struct, IConvertible
        {
            if (!EnumUtilities.IsDefined <TEnum>(value))
            {
                throw new System.ArgumentOutOfRangeException();
            }

            return((TEnum)((object)value));
        }
예제 #2
0
        public static TEnum Parse <TEnum>(string value) where TEnum : struct, IConvertible
        {
            TEnum result = (TEnum)Enum.Parse(typeof(TEnum), value);

            if (!EnumUtilities.IsDefined <TEnum>(value))
            {
                throw new System.ArgumentOutOfRangeException();
            }

            return(result);
        }
예제 #3
0
 public static bool TryParse <TEnum>(int value, out TEnum result) where TEnum : struct, IConvertible
 {
     if (EnumUtilities.IsDefined <TEnum>(value))
     {
         result = (TEnum)((object)value);
         return(true);
     }
     else
     {
         result = default;
         return(false);
     }
 }
예제 #4
0
 public static bool TryParse <TEnum>(string value, out TEnum result) where TEnum : struct, IConvertible
 {
     return(Enum.TryParse(value, out result) ? !EnumUtilities.IsDefined <TEnum>(value) : false);
 }