Skip to content

Commit 846f0fd

Browse files
authored
Remove call to .Any() from ProblemDetailsDefaultWriter (#43055)
* Remove call to .Any() * Removing System.Linq
1 parent 2d5f11b commit 846f0fd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Http/Http.Extensions/src/DefaultProblemDetailsWriter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics.CodeAnalysis;
5-
using System.Linq;
65
using System.Text.Json.Serialization;
76
using Microsoft.AspNetCore.Mvc;
87
using Microsoft.Extensions.Options;
@@ -26,9 +25,18 @@ public bool CanWrite(ProblemDetailsContext context)
2625
var httpContext = context.HttpContext;
2726
var acceptHeader = httpContext.Request.Headers.Accept.GetList<MediaTypeHeaderValue>();
2827

29-
if (acceptHeader?.Any(h => _jsonMediaType.IsSubsetOf(h) || _problemDetailsJsonMediaType.IsSubsetOf(h)) == true)
28+
if (acceptHeader is { Count: > 0 })
3029
{
31-
return true;
30+
for (var i = 0; i < acceptHeader.Count; i++)
31+
{
32+
var acceptHeaderValue = acceptHeader[i];
33+
34+
if (_jsonMediaType.IsSubsetOf(acceptHeaderValue) ||
35+
_problemDetailsJsonMediaType.IsSubsetOf(acceptHeaderValue))
36+
{
37+
return true;
38+
}
39+
}
3240
}
3341

3442
return false;

0 commit comments

Comments
 (0)