예제 #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));
            }
        }
예제 #2
0
파일: MediaRange.cs 프로젝트: ropean/Nancy
        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));
        }