public static string GetDescription(ErrorType type) { FieldInfo info = type.GetType().GetField(type.ToString()); DescriptionAttribute attr = (DescriptionAttribute)info.GetCustomAttribute(typeof(DescriptionAttribute)); return(attr != null ? attr.Description : ""); }
private async Task SendErrorMessage(ErrorType type, params string[] parameters) { var descriptionAttribute = type.GetType().GetField(type.ToString()).GetCustomAttribute <DescriptionAttribute>(false); var sendMessage = string.Empty; if (descriptionAttribute == null) { sendMessage = type.ToString(); } else { sendMessage = string.Format(descriptionAttribute.Description, parameters); } await m_userMessage.Channel.SendMessageAsync(sendMessage); }
public static string GetEnumDescription(ErrorType value) { var fi = value.GetType().GetField(value.ToString()); var attributes = (DescriptionAttribute[])fi.GetCustomAttributes( typeof(DescriptionAttribute), false); if (attributes != null && attributes.Length > 0) { return(attributes[0].Description); } else { return(value.ToString()); } }
private static string GetErrorType(ErrorType errorType) { var da = (DescriptionAttribute[])(errorType.GetType().GetField(errorType.ToString())).GetCustomAttributes(typeof(DescriptionAttribute), false); return(da.Length > 0 ? da[0].Description : errorType.ToString()); }