public static string GetDescription(this Enum value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            string str = value.ToString();
            EnumDescriptionAttribute enumDescriptionAttribute = value.GetEnumDescriptionAttribute();

            if (!string.IsNullOrEmpty(Extension.BuscarDescripcion(enumDescriptionAttribute)))
            {
                str = enumDescriptionAttribute.Description;
            }
            return(str);
        }
        public static EnumDescriptionAttribute GetEnumDescriptionAttribute(this Enum value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            EnumDescriptionAttribute enumDescriptionAttribute = null;
            string    str   = value.ToString();
            FieldInfo field = value.GetType().GetField(str);

            EnumDescriptionAttribute[] customAttributes = field.GetCustomAttributes(typeof(EnumDescriptionAttribute), false) as EnumDescriptionAttribute[];
            if ((customAttributes == null ? false : (int)customAttributes.Length > 0))
            {
                enumDescriptionAttribute = customAttributes[0];
            }
            return(enumDescriptionAttribute);
        }
        public static List <KeyValueTriplet <TKey, TNumericKey, string> > ToExtendedList <TKey, TNumericKey>(this Type type, bool incluirOcultos)
            where TKey : struct
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!type.IsEnum)
            {
                throw new InvalidCastException("El tipo no es un enumerador");
            }
            if (typeof(TKey) != type)
            {
                throw new InvalidCastException("Debe coincidir el Typo con el generic de TKey");
            }
            List <KeyValueTriplet <TKey, TNumericKey, string> > keyValueTriplets = new List <KeyValueTriplet <TKey, TNumericKey, string> >();

            foreach (Enum value in Extension.GetValues(type))
            {
                EnumDescriptionAttribute enumDescriptionAttribute = value.GetEnumDescriptionAttribute();
                string str  = value.ToString();
                bool   flag = true;
                KeyValueTriplet <TKey, TNumericKey, string> keyValueTriplet = new KeyValueTriplet <TKey, TNumericKey, string>()
                {
                    Key        = (TKey)Enum.Parse(type, str, true),
                    NumericKey = (TNumericKey)Convert.ChangeType(value, typeof(TNumericKey), CultureInfo.InvariantCulture),
                    Value      = str
                };
                KeyValueTriplet <TKey, TNumericKey, string> keyValueTriplet1 = keyValueTriplet;
                if (enumDescriptionAttribute != null)
                {
                    flag = (!enumDescriptionAttribute.Ocultar ? true : incluirOcultos);
                    string str1 = Extension.BuscarDescripcion(enumDescriptionAttribute);
                    if (!string.IsNullOrEmpty(str1))
                    {
                        keyValueTriplet1.Value = str1;
                    }
                }
                if (flag)
                {
                    keyValueTriplets.Add(keyValueTriplet1);
                }
            }
            return(keyValueTriplets);
        }
        private static string BuscarDescripcion(EnumDescriptionAttribute attribute)
        {
            string empty = string.Empty;

            if ((attribute == null ? false : !string.IsNullOrEmpty(attribute.Description)))
            {
                empty = attribute.Description;
                if (attribute.TipoRecurso != null)
                {
                    PropertyInfo property = attribute.TipoRecurso.GetProperty(empty, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                    if (property != null)
                    {
                        empty = property.GetValue(null, null) as string;
                    }
                }
            }
            return(empty);
        }