public static Nullable <TEnum> ParseNullable <TEnum>(Object value) where TEnum : struct
        {
            Nullable <TEnum> result = null;

            if (value == null || value == DBNull.Value)
            {
                result = null;
            }

            else if (value is String)
            {
                result = EnumEx.Parse <TEnum>((String)value);
            }

            else if (value is Char)
            {
                result = EnumEx.Parse <TEnum>((Char)value);
            }

            else if (value is Int32)
            {
                result = EnumEx.Parse <TEnum>((Int32)value);
            }

            return(result);
        }
        public static List <String> GetDescriptions(Type enumType)
        {
            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new Exception(String.Format("{0} must be an enum type", enumType));
            }

            List <String> result = new List <String>();

            List <Enum> values = EnumEx.ToEnumList(enumType);

            foreach (Enum value in values)
            {
                result.Add(value.ToDescription());
            }

            return(result);
        }
 public static TEnum Parse <TEnum>(Object value) where TEnum : struct
 {
     return(EnumEx.ParseNullable <TEnum>(value).Value);
 }
        public void ToNameTEnum_WithAttrib_EqualsFirstName()
        {
            var name = EnumEx.ToName <TestEnum>(TestEnum.WithAttrib);

            Assert.AreEqual("With Attrib", name);
        }
        public void ToName_WithAttrib_EqualsFirstName()
        {
            var name = EnumEx.ToName(typeof(TestEnum), TestEnum.WithAttrib);

            Assert.AreEqual("With Attrib", name);
        }
        public void ToNameTEnum_OutOfRange_IsNull()
        {
            var name = EnumEx.ToName <TestEnum>((TestEnum)3);

            Assert.AreEqual("3", name);
        }
        public void ToName_OutOfRange_IsNull()
        {
            var name = EnumEx.ToName(typeof(TestEnum), (TestEnum)3);

            Assert.AreEqual("3", name);
        }