Exemple #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();
        }
Exemple #2
0
        /// <summary>
        /// Whether or not a set of media range parameters matches another, regardless of order
        /// </summary>
        /// <param name="other">Other media range parameters</param>
        /// <returns>True if matching, false if not</returns>
        public bool Matches(MediaRangeParameters other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            return(parameters.OrderBy(p => p.Key).SequenceEqual(other.parameters.OrderBy(p => p.Key)));
        }
Exemple #3
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));
 }