本文整理汇总了C#中HttpHeaderValueCollection.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# HttpHeaderValueCollection.OrderByDescending方法的具体用法?C# HttpHeaderValueCollection.OrderByDescending怎么用?C# HttpHeaderValueCollection.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeaderValueCollection
的用法示例。
在下文中一共展示了HttpHeaderValueCollection.OrderByDescending方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}