public static string ToNiceDisplayName(this Enum value) { string result = value.ToString(); //try NiceDisplayName if (value.GetType().GetCustomAttributes(false).Length > 0) { foreach (object o in value.GetType().GetCustomAttributes(false)) { if (o.GetType() == typeof(ShowNiceDisplayNameAttribute)) { //look for NiceDisplayAttribute object[] attributes = value.GetType().GetField(result).GetCustomAttributes(false); if (attributes.Length > 0) { foreach (object oa in attributes) { if (oa.GetType() == typeof(NiceDisplayNameAttribute)) { NiceDisplayNameAttribute dnn = (NiceDisplayNameAttribute)oa; return(dnn.DisplayName); } } } } } } return(result); }
public static string GetNiceDisplayName(FieldInfo field) { if (field != null) { object[] attributes = field.GetCustomAttributes(false); if (attributes.Length > 0) { foreach (object o in attributes) { if (o.GetType() == typeof(NiceDisplayNameAttribute)) { NiceDisplayNameAttribute dnn = (NiceDisplayNameAttribute)o; return(dnn.DisplayName); } } } } return(null); }