public AcceptType(String AcceptString, Double Quality) { #region Initial checks if (AcceptString.IsNullOrEmpty()) { throw new ArgumentNullException("The given Accept string must not be null or empty!"); } #endregion this.ContentType = HTTPContentType.ForMediaType(AcceptString, () => new HTTPContentType(AcceptString)); this.Quality = Quality; }
/// <summary> /// Parse the string representation of a HTTP accept header field. /// </summary> /// <param name="AcceptString"></param> public AcceptType(String AcceptString) { this.Quality = 1; var SplittedAcceptString = AcceptString.Split(new Char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries); switch (SplittedAcceptString.Length) { case 1: ContentType = HTTPContentType.ForMediaType(AcceptString, () => new HTTPContentType(AcceptString)); Quality = 1.0; break; case 2: this.ContentType = HTTPContentType.ForMediaType(AcceptString, () => new HTTPContentType(SplittedAcceptString[0])); this.Quality = Double.Parse(SplittedAcceptString[1].Substring(2)); break; default: throw new ArgumentException("Could not parse the given AcceptString!"); } }