public static string GetDescription(StatusCode value) { FieldInfo fi = value.GetType().GetField(value.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes != null && attributes.Length > 0) { return(attributes[0].Description); } else { return(value.ToString()); } }
public override string ToString() { StringBuilder response = new StringBuilder(); response.Append(Constants.HttpOneProtocolFragment); string statusText = Enumerator.ToTextOrDefault(StatusCode.GetType(), StatusCode); response.Append($" {statusText}"); response.Append(Environment.NewLine); if (Headers.Any()) { response.Append(Headers.ToString()); } if (Cookies.Any()) { response.Append(Constants.CookieResponseHeaderKey); response.Append($": {Cookies.ToString()}"); } response.Append(Environment.NewLine); return(response.ToString()); }
public static string GetStatusDescription(StatusCode code) { return(code.GetType().GetMember(Enum.GetName(code.GetType(), code)).Single(). GetCustomAttributes(typeof(DescriptionAttribute), false).Cast <DescriptionAttribute>().Single().Description); }