Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaRange"/> class from a string representation of a media range
        /// </summary>
        /// <param name="contentType">the content type</param>
        public MediaRange(string contentType) : this()
        {
            if (string.IsNullOrEmpty(contentType))
            {
                throw new ArgumentException("inputString cannot be null or empty", contentType);
            }

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

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

            if (parts.Length < 2)
            {
                {
                    throw new ArgumentException("inputString not in correct Type/SubType format", contentType);
                }
            }

            this.Type    = parts[0];
            this.Subtype = parts[1].TrimEnd();

            if (parts.Length > 2)
            {
                var separator = contentType.IndexOf(';');
                this.Parameters = MediaRangeParameters.FromString(contentType.Substring(separator));
            }
        }
Example #2
0
        private void ParseContentType(string contentType)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                this.Type       = string.Empty;
                this.Subtype    = string.Empty;
                this.Parameters = new MediaRangeParameters();
                return;
            }

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

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

            if (parts.Length < 2)
            {
                {
                    throw new ArgumentException("inputString not in correct Type/SubType format", contentType);
                }
            }

            this.Type    = parts[0];
            this.Subtype = parts[1].TrimEnd();

            if (parts.Length <= 2)
            {
                this.Parameters = new MediaRangeParameters();
                return;
            }

            var separator = contentType.IndexOf(';');

            this.Parameters = MediaRangeParameters.FromString(contentType.Substring(separator));
        }
Example #3
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)
 {
     return(this.parameters.OrderBy(p => p.Key).SequenceEqual(other.parameters.OrderBy(p => p.Key)));
 }