public override bool Equals(object obj) { if (obj == this) { return(true); } EnumLabelAttribute other = obj as EnumLabelAttribute; return((other != null) && other.Label == Label); }
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); }