Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            EnumLabelAttribute other = obj as EnumLabelAttribute;

            return((other != null) && other.Label == Label);
        }
Ejemplo n.º 2
0
        public static string GetLabel(this Enum value)
        {
            Type   type = value.GetType();
            string name = Enum.GetName(type, value);

            if (name != null)
            {
                FieldInfo field = type.GetField(name);
                if (field != null)
                {
                    EnumLabelAttribute attr = Attribute.GetCustomAttribute(field, typeof(EnumLabelAttribute)) as EnumLabelAttribute;
                    if (attr != null)
                    {
                        return(attr.Label);
                    }
                }
            }

            return(string.Empty);
        }