public void TestCreateEnumTypeWithCorrectInput()
        {
            Type result = enumGenerator.CreateEnumType(enumDescriptor);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsEnum);
            Assert.AreEqual("e1", result.GetEnumNames().GetValue(0));
            Assert.AreEqual(1, Convert.ChangeType(result.GetEnumValues().GetValue(0), result.GetEnumUnderlyingType()));
            Assert.IsTrue(result.GetEnumUnderlyingType() == typeof(int));
            Assert.IsTrue(result.GetCustomAttributes(false).Single(attribute => attribute.GetType() == typeof(FlagsAttribute)) != null);
        }
Example #2
0
        public IEnumHelper AddEnumType(IEnumDescriptor enumDescriptor)
        {
            if (enumDescriptor == null)
            {
                throw new ArgumentNullException();
            }

            if (!EnumDictionary.ContainsKey(enumDescriptor.EnumName))
            {
                Type enumType = _enumGenerator.CreateEnumType(enumDescriptor);

                EnumDictionary.Add(enumDescriptor.EnumName, new EnumHelper(enumType, enumDescriptor));
            }

            return(EnumDictionary[enumDescriptor.EnumName]);
        }