Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaRange"/> class.
        /// </summary>
        /// <param name="value"></param>
        MediaRange(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentOutOfRangeException(nameof(value));
            }

            if (value.Equals("*"))
            {
                value = "*/*";
            }

            var parts = value.Split('/', ';');

            if (parts.Length < 2)
            {
                throw new ArgumentException("Content type not in correct 'type/subType' format.", value);
            }

            this.type       = parts[0];
            this.subtype    = parts[1].TrimEnd();
            this.parameters = parts.Length > 2 ? MediaRangeParameters.Parse(value.Substring(value.IndexOf(';'))) : new MediaRangeParameters();
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaRange"/> class.
 /// </summary>
 MediaRange(MediaRangePart type, MediaRangePart subtype, MediaRangeParameters parameters)
 {
     this.type       = type;
     this.subtype    = subtype;
     this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters));
 }
Esempio n. 3
0
 /// <summary>
 /// Matched the media type with another media type.
 /// </summary>
 /// <param name="other">The media type that should be matched against.</param>
 /// <returns><see langword="true" /> if the media types match, otherwise <see langword="false" />.</returns>
 public bool Matches(MediaRangePart other)
 {
     return(IsWildcard || other.IsWildcard || value.Equals(other.value));
 }