Пример #1
0
        // Token: 0x06001727 RID: 5927 RVA: 0x0006D760 File Offset: 0x0006B960
        public static IList <Class_506 <TUnderlyingType> > GetNamesAndValues <TUnderlyingType>(Type enumType) where TUnderlyingType : struct
        {
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }
            Class_517.ArgumentTypeIsEnum(enumType, "enumType");
            IList <object> values = Class_505.GetValues(enumType);
            IList <string> names  = Class_505.GetNames(enumType);
            IList <Class_506 <TUnderlyingType> > list = new List <Class_506 <TUnderlyingType> >();

            for (int i = 0; i < values.Count; i++)
            {
                try
                {
                    list.Add(new Class_506 <TUnderlyingType>(names[i], (TUnderlyingType)((object)Convert.ChangeType(values[i], typeof(TUnderlyingType), CultureInfo.CurrentCulture))));
                }
                catch (OverflowException innerException)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Value from enum with the underlying type of {0} cannot be added to dictionary with a value type of {1}. Value was too large: {2}", new object[]
                    {
                        Enum.GetUnderlyingType(enumType),
                        typeof(TUnderlyingType),
                        Convert.ToUInt64(values[i], CultureInfo.InvariantCulture)
                    }), innerException);
                }
            }
            return(list);
        }