/// <summary>Creates a new instance of the <see cref="T:NMasters.Silverlight.Net.Http.Content.StringContent" /> class.</summary>
 /// <param name="content">The content used to initialize the <see cref="T:NMasters.Silverlight.Net.Http.Content.StringContent" />.</param>
 /// <param name="encoding">The encoding to use for the content.</param>
 /// <param name="mediaType">The media type to use for the content.</param>
 public StringContent(string content, Encoding encoding, string mediaType)
     : base(GetContentByteArray(content, encoding))
 {
     MediaTypeHeaderValue value2 = new MediaTypeHeaderValue((mediaType == null) ? "text/plain" : mediaType) {
         CharSet = (encoding == null) ? HttpContent.DefaultStringEncoding.WebName : encoding.WebName
     };
     base.Headers.ContentType = value2;
 }
        /// <summary>
        /// Initializes a new instance of a <see cref="MediaTypeMapping"/> with the
        /// given <paramref name="mediaType"/> value.
        /// </summary>
        /// <param name="mediaType">
        /// The <see cref="string"/> that is associated with <see cref="HttpRequestMessage"/> or 
        /// <see cref="HttpResponseMessage"/> instances that have the given characteristics of the 
        /// <see cref="MediaTypeMapping"/>.
        /// </param>
        protected MediaTypeMapping(string mediaType)
        {
            if (String.IsNullOrWhiteSpace(mediaType))
            {
                throw Error.ArgumentNull("mediaType");
            }

            MediaType = new MediaTypeHeaderValue(mediaType);
        }
        /// <summary>
        /// Initializes a new instance of a <see cref="MediaTypeMapping"/> with the
        /// given <paramref name="mediaType"/> value.
        /// </summary>
        /// <param name="mediaType">
        /// The <see cref="MediaTypeHeaderValue"/> that is associated with <see cref="HttpRequestMessage"/> or 
        /// <see cref="HttpResponseMessage"/> instances that have the given characteristics of the 
        /// <see cref="MediaTypeMapping"/>.
        /// </param>
        protected MediaTypeMapping(MediaTypeHeaderValue mediaType)
        {
            if (mediaType == null)
            {
                throw Error.ArgumentNull("mediaType");
            }

            MediaType = mediaType;
        }
 /// <summary>Initializes a new instance of the <see cref="T:NMasters.Silverlight.Net.Http.Headers.MediaTypeHeaderValue" /> class.</summary>
 protected MediaTypeHeaderValue(MediaTypeHeaderValue source)
 {
     this.mediaType = source.mediaType;
     if (source.parameters != null)
     {
         foreach (NameValueHeaderValue value2 in source.parameters)
         {
             this.Parameters.Add((NameValueHeaderValue)((ICloneable)value2).Clone());
         }
     }
 }
        public ParsedMediaTypeHeaderValue(MediaTypeHeaderValue mediaType)
        {
            Contract.Assert(mediaType != null, "The 'mediaType' parameter should not be null.");

            string[] splitMediaType = mediaType.MediaType.Split(MediaTypeSubtypeDelimiter);

            Contract.Assert(splitMediaType.Length == 2, "The constructor of the MediaTypeHeaderValue would have failed if there wasn't a type and subtype.");

            _type = splitMediaType[0];
            _subType = splitMediaType[1];
        }
        /// <summary>
        /// Determines whether two <see cref="MediaTypeHeaderValue"/> instances match. The instance
        /// <paramref name="mediaType1"/> is said to match <paramref name="mediaType2"/> if and only if
        /// <paramref name="mediaType1"/> is a strict subset of the values and parameters of <paramref name="mediaType2"/>. 
        /// That is, if the media type and media type parameters of <paramref name="mediaType1"/> are all present 
        /// and match those of <paramref name="mediaType2"/> then it is a match even though <paramref name="mediaType2"/> may have additional
        /// parameters.
        /// </summary>
        /// <param name="mediaType1">The first media type.</param>
        /// <param name="mediaType2">The second media type.</param>
        /// <param name="mediaType2Range">Indicates whether <paramref name="mediaType2"/> is a regular media type, a subtype media range, or a full media range</param>
        /// <returns><c>true</c> if this is a subset of <paramref name="mediaType2"/>; false otherwise.</returns>
        public static bool IsSubsetOf(this MediaTypeHeaderValue mediaType1, MediaTypeHeaderValue mediaType2, out MediaTypeHeaderValueRange mediaType2Range)
        {
            Contract.Assert(mediaType1 != null);

            if (mediaType2 == null)
            {
                mediaType2Range = MediaTypeHeaderValueRange.None;
                return false;
            }

            ParsedMediaTypeHeaderValue parsedMediaType1 = new ParsedMediaTypeHeaderValue(mediaType1);
            ParsedMediaTypeHeaderValue parsedMediaType2 = new ParsedMediaTypeHeaderValue(mediaType2);
            mediaType2Range = parsedMediaType2.IsAllMediaRange ? MediaTypeHeaderValueRange.AllMediaRange :
                parsedMediaType2.IsSubtypeMediaRange ? MediaTypeHeaderValueRange.SubtypeMediaRange :
                MediaTypeHeaderValueRange.None;

            if (!String.Equals(parsedMediaType1.Type, parsedMediaType2.Type, StringComparison.OrdinalIgnoreCase))
            {
                if (mediaType2Range != MediaTypeHeaderValueRange.AllMediaRange)
                {
                    return false;
                }
            }
            else if (!String.Equals(parsedMediaType1.Subtype, parsedMediaType2.Subtype, StringComparison.OrdinalIgnoreCase))
            {
                if (mediaType2Range != MediaTypeHeaderValueRange.SubtypeMediaRange)
                {
                    return false;
                }
            }

            // So far we either have a full match or a subset match. Now check that all of
            // mediaType1's parameters are present and equal in mediatype2
            foreach (NameValueHeaderValue parameter1 in mediaType1.Parameters)
            {
                if (!mediaType2.Parameters.Any(parameter2 => parameter1.Equals(parameter2)))
                {
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectContent"/> class.
        /// </summary>
        /// <param name="type">The type of object this instance will contain.</param>
        /// <param name="value">The value of the object this instance will contain.</param>
        /// <param name="formatter">The formatter to use when serializing the value.</param>
        /// <param name="mediaType">The authoritative value of the content's Content-Type header. Can be <c>null</c> in which case the
        /// <paramref name="formatter">formatter's</paramref> default content type will be used.</param>
        public ObjectContent(Type type, object value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType)
        {
            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }
            if (formatter == null)
            {
                throw Error.ArgumentNull("formatter");
            }

            if (!formatter.CanWriteType(type))
            {
                throw Error.InvalidOperation(FSR.ObjectContent_FormatterCannotWriteType, formatter.GetType().FullName, type.Name);
            }

            _formatter = formatter;
            ObjectType = type;

            VerifyAndSetObject(value);
            _formatter.SetDefaultContentHeaders(type, Headers, mediaType);
        }
 /// <summary>
 /// Determines whether two <see cref="MediaTypeHeaderValue"/> instances match. The instance
 /// <paramref name="mediaType1"/> is said to match <paramref name="mediaType2"/> if and only if
 /// <paramref name="mediaType1"/> is a strict subset of the values and parameters of <paramref name="mediaType2"/>. 
 /// That is, if the media type and media type parameters of <paramref name="mediaType1"/> are all present 
 /// and match those of <paramref name="mediaType2"/> then it is a match even though <paramref name="mediaType2"/> may have additional
 /// parameters.
 /// </summary>
 /// <param name="mediaType1">The first media type.</param>
 /// <param name="mediaType2">The second media type.</param>
 /// <returns><c>true</c> if this is a subset of <paramref name="mediaType2"/>; false otherwise.</returns>
 public static bool IsSubsetOf(this MediaTypeHeaderValue mediaType1, MediaTypeHeaderValue mediaType2)
 {
     MediaTypeHeaderValueRange mediaType2Range;
     return IsSubsetOf(mediaType1, mediaType2, out mediaType2Range);
 }
 internal static int GetMediaTypeLength(string input, int startIndex, Func<MediaTypeHeaderValue> mediaTypeCreator, out MediaTypeHeaderValue parsedValue)
 {
     parsedValue = null;
     if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
     {
         return 0;
     }
     string mediaType = null;
     int num = GetMediaTypeExpressionLength(input, startIndex, out mediaType);
     if (num == 0)
     {
         return 0;
     }
     int num2 = startIndex + num;
     num2 += HttpRuleParser.GetWhitespaceLength(input, num2);
     MediaTypeHeaderValue value2 = null;
     if ((num2 < input.Length) && (input[num2] == ';'))
     {
         value2 = mediaTypeCreator.Invoke();
         value2.mediaType = mediaType;
         num2++;
         int num3 = NameValueHeaderValue.GetNameValueListLength(input, num2, ';', value2.Parameters);
         if (num3 == 0)
         {
             return 0;
         }
         parsedValue = value2;
         return ((num2 + num3) - startIndex);
     }
     value2 = mediaTypeCreator.Invoke();
     value2.mediaType = mediaType;
     parsedValue = value2;
     return (num2 - startIndex);
 }
        /// <summary>Creates a new object that is a copy of the current <see cref="T:NMasters.Silverlight.Net.Http.Headers.MediaTypeHeaderValue" /> instance.</summary>
        /// <returns>Returns <see cref="T:System.Object" />.A copy of the current instance.</returns>
        public MediaTypeHeaderValue Clone()
        {
            var result = new MediaTypeHeaderValue(this.mediaType);
            foreach (var parameter in this.Parameters)
            {
                result.Parameters.Add(new NameValueHeaderValue(parameter.Name, parameter.Value));
            }

            return result;
        }
 /// <summary>Determines whether a string is valid <see cref="T:NMasters.Silverlight.Net.Http.Headers.MediaTypeHeaderValue" /> information.</summary>
 /// <returns>Returns <see cref="T:System.Boolean" />.true if <paramref name="input" /> is valid <see cref="T:NMasters.Silverlight.Net.Http.Headers.MediaTypeHeaderValue" /> information; otherwise, false.</returns>
 /// <param name="input">The string to validate.</param>
 /// <param name="parsedValue">The <see cref="T:NMasters.Silverlight.Net.Http.Headers.MediaTypeHeaderValue" /> version of the string.</param>
 public static bool TryParse(string input, out MediaTypeHeaderValue parsedValue)
 {
     object obj2;
     int index = 0;
     parsedValue = null;
     if (MediaTypeHeaderParser.SingleValueParser.TryParseValue(input, null, ref index, out obj2))
     {
         parsedValue = (MediaTypeHeaderValue) obj2;
         return true;
     }
     return false;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RequestHeaderMapping"/> class.
 /// </summary>
 /// <param name="headerName">Name of the header to match.</param>
 /// <param name="headerValue">The header value to match.</param>
 /// <param name="valueComparison">The <see cref="StringComparison"/> to use when matching <paramref name="headerValue"/>.</param>
 /// <param name="isValueSubstring">if set to <c>true</c> then <paramref name="headerValue"/> is 
 /// considered a match if it matches a substring of the actual header value.</param>
 /// <param name="mediaType">The <see cref="MediaTypeHeaderValue"/> to use if <paramref name="headerName"/> and <paramref name="headerValue"/> 
 /// is considered a match.</param>
 public RequestHeaderMapping(string headerName, string headerValue, StringComparison valueComparison, bool isValueSubstring, MediaTypeHeaderValue mediaType)
     : base(mediaType)
 {
     Initialize(headerName, headerValue, valueComparison, isValueSubstring);
 }