/// <summary> /// Verifies that a header name matches name of the associate header, with MIME string comparison semantics. /// </summary> /// <param name="name">The header name to verify</param> /// <param name="header">The <see cref="Header"/> to verify against.</param> static void VerifyName(string name, Header header) { if (!MimeStandard.Equals(name, header.Name)) { throw new MimeException(MimeError.InvalidHeader); } }
/// <summary> /// Returns all values for the given paramName /// </summary> /// <param name="paramName"></param> /// <returns></returns> public IEnumerable <string> GetValues(string paramName) { return( from nv in this where MimeStandard.Equals(nv.Key, paramName) select nv.Value ); }
/// <summary> /// Tests if this header is named the supplied <paramref name="name"/> /// </summary> /// <param name="name">The name to test this header's name against</param> /// <returns><c>true</c> if the names match by MIME string comparison rules</returns> public bool IsNamed(string name) { if (string.IsNullOrEmpty(name)) { return(false); } return(MimeStandard.Equals(this.Name, name)); }
/// <summary> /// Tests if this entity has the named header with a value, using MIME-appropriate string comparison. /// </summary> /// <param name="name">The header name to test for.</param> /// <param name="value">The value to test</param> /// <returns><c>true</c> if the entity has the named header and the header has the appropriate value, <c>false</c> otherwise</returns> public bool HasHeader(string name, string value) { if (!this.HasHeaders) { return(false); } Header header = m_headers[name]; return(header != null && MimeStandard.Equals(header.Value, value)); }
/// <summary> /// Tests if this content type has the named parameter and parameter value. /// </summary> /// <param name="contentType">The content type to test</param> /// <param name="parameter">The parameter name to test</param> /// <param name="value">The parameter value to test</param> /// <returns><c>true</c> if the content type has the named parameter with the parameter value</returns> public static bool HasParameter(this ContentType contentType, string parameter, string value) { string paramValue = contentType.Parameters[parameter]; if (paramValue == null) { return(false); } return(MimeStandard.Equals(paramValue, value)); }
/// <summary> /// Return the index of the first matching field /// </summary> /// <param name="field"></param> /// <returns>-1 if field not found. Else >= 0</returns> public int IndexOfFirst(KeyValuePair <string, string> field) { for (int i = 0, count = this.Count; i < count; ++i) { KeyValuePair <string, string> foundField = this[i]; if (MimeStandard.Equals(foundField.Key, field.Key) && MimeStandard.Equals(foundField.Value, field.Value) ) { return(i); } } return(-1); }
/// <summary> /// Returns the index of the first parameter with this name /// </summary> /// <param name="paramName"></param> /// <returns></returns> public int IndexOfFirst(string paramName) { if (string.IsNullOrEmpty(paramName)) { throw new ArgumentException("paramName"); } for (int i = 0, count = this.Count; i < count; ++i) { if (MimeStandard.Equals(this[i].Key, paramName)) { return(i); } } return(-1); }
/// <summary> /// Returns the index to a header name. See <see cref="HeaderCollection"/> for more details. /// </summary> /// <remarks> /// Headers are not case sensitive, so <c>myHeaders.IndexOf("content-type")</c> and /// <c>myHeaders.IndexOf("Content-Type")</c> /// will refer to the same header value. /// </remarks> /// <param name="name">The name of the header to get or set. See remarks.</param> /// <returns>The zero-based index of the named header or -1 if the header was not found.</returns> public int IndexOf(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("name was null or empty", "name"); } for (int i = 0, count = Count; i < count; ++i) { if (MimeStandard.Equals(this[i].Name, name)) { return(i); } } return(-1); }
/// <summary> /// Tests if this header is named one of the supplied <paramref name="names"/> /// </summary> /// <param name="names">The names to test this header's name against</param> /// <returns><c>true</c> if this header matches one of the supplied names match by MIME string comparison rules</returns> public bool IsHeaderNameOneOf(string[] names) { if (names == null || names.Length == 0) { return(false); } string name = this.Name; for (int i = 0; i < names.Length; ++i) { if (MimeStandard.Equals(names[i], name)) { return(true); } } return(false); }
/// <summary> /// Tests if this collection has the named header with a value, using MIME-appropriate string comparison. /// </summary> /// <param name="name">The header name to test for.</param> /// <param name="value">The value to test</param> /// <returns><c>true</c> if the collection has the named header and the header has the appropriate value, <c>false</c> otherwise</returns> public bool HasHeader(string name, string value) { Header header = this[name]; return(header != null && MimeStandard.Equals(header.Value, value)); }
/// <summary> /// Tests if this content type is same one represented by the specified <paramref name="mediaType"/> /// </summary> /// <param name="contentType">This <see cref="ContentType"/></param> /// <param name="mediaType">The content type string to test against this instance.</param> /// <returns></returns> public static bool IsMediaType(this ContentType contentType, string mediaType) { return(MimeStandard.Equals(contentType.MediaType, mediaType)); }