当前位置: 首页>>代码示例>>C#>>正文


C# HttpHeaderValueCollection.Any方法代码示例

本文整理汇总了C#中HttpHeaderValueCollection.Any方法的典型用法代码示例。如果您正苦于以下问题:C# HttpHeaderValueCollection.Any方法的具体用法?C# HttpHeaderValueCollection.Any怎么用?C# HttpHeaderValueCollection.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpHeaderValueCollection的用法示例。


在下文中一共展示了HttpHeaderValueCollection.Any方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsRequestedMediaTypeAccepted

 private static bool IsRequestedMediaTypeAccepted(HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> acceptHeader)
 {
     return GlobalConfiguration
         .Configuration
         .Formatters
         .Any(formatter => acceptHeader.Any(mediaType => FormatterSuportsMediaType(mediaType, formatter)));
 }
开发者ID:rmueller,项目名称:WebAPIContrib,代码行数:7,代码来源:NotAcceptableMessageHandler.cs

示例2: GetEncoder

        public Func<Stream, Stream> GetEncoder(HttpHeaderValueCollection<StringWithQualityHeaderValue> list)
        {
            // The following steps will walk you through
            // completing the implementation of this method
            if (list != null && list.Count > 0)
            {
                // More code goes here
                var headerValue = list.OrderByDescending(e => e.Quality ?? 1.0D).Where(e => !e.Quality.HasValue || e.Quality.Value > 0.0D).FirstOrDefault(e => supported.Keys.Contains(e.Value, StringComparer.OrdinalIgnoreCase));
                // Case 1: We can support what client has asked for
                if (headerValue != null)
                    return GetStreamForSchema(headerValue.Value);
                // Case 2: Client will accept anything we support except
                // the ones explicitly specified as not preferred by setting q=0
                if (list.Any(e => e.Value == "*" &&
                (!e.Quality.HasValue || e.Quality.Value > 0.0D)))
                {
                    var encoding = supported.Keys.Where(se =>
                    !list.Any(e =>
                    e.Value.Equals(se, StringComparison.OrdinalIgnoreCase) &&
                    e.Quality.HasValue &&
                    e.Quality.Value == 0.0D))
                    .FirstOrDefault();
                    if (encoding != null)
                        return GetStreamForSchema(encoding);
                }

                // Case 3: Client specifically refusing identity
                if (list.Any(e => e.Value.Equals(IDENTITY, StringComparison.OrdinalIgnoreCase) &&
                e.Quality.HasValue && e.Quality.Value == 0.0D))
                {
                    throw new NegotiationFailedException();
                }
                // Case 4: Client is not willing to accept any of the encodings
                // we support and is not willing to accept identity
                if (list.Any(e => e.Value == "*" &&
                (e.Quality.HasValue || e.Quality.Value == 0.0D)))
                {
                    if (!list.Any(e => e.Value.Equals(IDENTITY, StringComparison.OrdinalIgnoreCase)))
                        throw new NegotiationFailedException();
                }
            }
            // Settle for the default, which is no transformation whatsoever
            return null;
        }
开发者ID:KaranGandhi,项目名称:TestDemo,代码行数:44,代码来源:EncodingSchema.cs

示例3: ValidateAcceptsSData

        private bool ValidateAcceptsSData(HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> acceptHeader)
        {
            if (acceptHeader != null && !acceptHeader.Any(x => x.MediaType == ALL_MEDIA_TYPE))
            {
                bool acceptsJson = acceptHeader.Any(x => x.MediaType == JSON_MEDIA_TYPE);

                if (!acceptsJson)
                {
                    return false;
                }

                bool acceptsSData = acceptHeader.Any(x => x.MediaType == JSON_MEDIA_TYPE &&
                                    x.Parameters.Any(p => p.Name == SDATA_MEDIA_TYPE_VALUE_VND));

                if (!acceptsSData)
                {
                    // does not mention SData check if OData mentioned
                    bool acceptsOData = acceptHeader.Any(x => x.MediaType == JSON_MEDIA_TYPE &&
                                        x.Parameters.Any(p => p.Name == ODATA_MEDIA_TYPE_VALUE_VND));

                    if (acceptsOData)
                    {
                        // OData JSON Request; i.e. Accept header equals: application/json;odata=[verbose, etc]
                        return false;
                    }

                    // consumer asked for JSON but did not indicated SData or OData so default is return SData; just continue
                }
            }

            return true;
        }
开发者ID:jaretts,项目名称:ODataSDataDemo,代码行数:32,代码来源:SDataMessageHandler.cs


注:本文中的HttpHeaderValueCollection.Any方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。