Пример #1
0
        //Retruns the name of the color for a given color code...
        private WebColorEnum GetValueByDescription(string description)
        {
            WebColorEnum wbc      = WebColorEnum.Alice_Blue;
            Type         enumType = typeof(WebColorEnum);

            foreach (var field in enumType.GetFields())
            {
                DescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
                if (attribute != null)
                {
                    if (attribute.Description == description)
                    {
                        wbc = (WebColorEnum)field.GetValue(null);
                        break;
                    }
                    else
                    {
                        if (field.Name == description)
                        {
                            wbc = (WebColorEnum)field.GetValue(null);
                            break;
                        }
                    }
                }
            }

            return(wbc);
        }
Пример #2
0
        // Gets the RGB color value attached to each field in WebColor enum as a string..
        private string GetDescriptionByValue(WebColorEnum value)
        {
            Type      type  = value.GetType();
            string    name  = Enum.GetName(type, value);
            FieldInfo field = type.GetField(name);

            DescriptionAttribute att = (DescriptionAttribute)Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));

            return(att.Description);
        }