public RespDataBase(HttpResponseCode code) { this.Code = ((int)code).ToString(); var filed = code.GetType().GetField(code.ToString()); this.Message = ((DescriptionAttribute)filed.GetCustomAttributes(typeof(DescriptionAttribute), true).First()).Description; }
public static string GetDescription(this HttpResponseCode val) { DescriptionAttribute[] attributes = (DescriptionAttribute[])val .GetType() .GetField(val.ToString()) .GetCustomAttributes(typeof(DescriptionAttribute), false); return(attributes.Length > 0 ? attributes[0].Description : string.Empty); }