예제 #1
0
        private Encoding SelectCharacterEncoding(ContentTypeHeaderValue contentType)
        {
            if (contentType != null)
            {
                // Find encoding based on content type charset parameter
                var charset = contentType.CharSet;
                if (!string.IsNullOrWhiteSpace(contentType.CharSet))
                {
                    for (var i = 0; i < _supportedEncodings.Count; i++)
                    {
                        var supportedEncoding = _supportedEncodings[i];
                        if (string.Equals(charset, supportedEncoding.WebName, StringComparison.OrdinalIgnoreCase))
                        {
                            return(supportedEncoding);
                        }
                    }
                }
            }

            if (_supportedEncodings.Count > 0)
            {
                return(_supportedEncodings[0]);
            }

            // No supported encoding was found so there is no way for us to start reading.
            throw new InvalidOperationException(Resources.FormatMediaTypeFormatterNoEncoding(GetType().FullName));
        }
예제 #2
0
        /// Internal because ContentTypeHeaderValue is internal.
        internal static Encoding SelectCharacterEncoding(IList<Encoding> supportedEncodings,
            ContentTypeHeaderValue contentType, Type callerType)
        {
            if (contentType != null)
            {
                // Find encoding based on content type charset parameter
                var charset = contentType.CharSet;
                if (!string.IsNullOrWhiteSpace(contentType.CharSet))
                {
                    for (var i = 0; i < supportedEncodings.Count; i++)
                    {
                        var supportedEncoding = supportedEncodings[i];
                        if (string.Equals(charset, supportedEncoding.WebName, StringComparison.OrdinalIgnoreCase))
                        {
                            return supportedEncoding;
                        }
                    }
                }
            }

            if (supportedEncodings.Count > 0)
            {
                return supportedEncodings[0];
            }

            // No supported encoding was found so there is no way for us to start reading.
            throw new InvalidOperationException(Resources.FormatMediaTypeFormatterNoEncoding(callerType.FullName));
        }
예제 #3
0
 private bool IsSupportedContentType(ContentTypeHeaderValue contentType)
 {
     return contentType != null &&
            _supportedMediaTypes.Contains(contentType.ContentType, StringComparer.OrdinalIgnoreCase);
 }
예제 #4
0
 private bool IsSupportedContentType(ContentTypeHeaderValue contentType)
 {
     return(contentType != null &&
            _supportedMediaTypes.Contains(contentType.ContentType, StringComparer.OrdinalIgnoreCase));
 }