diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeRenderingContext.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeRenderingContext.cs index f1aa24ad79d..b9e02d9c159 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeRenderingContext.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeRenderingContext.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; using Microsoft.AspNetCore.Razor.Language.Intermediate; using Microsoft.AspNetCore.Razor.PooledObjects; @@ -98,9 +97,16 @@ public ImmutableArray GetDiagnostics() // Filter out diagnostics whose warning level exceeds the configured level. // Diagnostics with level 0 are always reported regardless of the configured level. - return _diagnostics - .Where(d => d.WarningLevel <= warningLevel) - .OrderByAsArray(static d => d.Span.AbsoluteIndex); + using var filtered = new PooledArrayBuilder(capacity: _diagnostics.Count); + foreach (var diagnostic in _diagnostics) + { + if (diagnostic.WarningLevel <= warningLevel) + { + filtered.Add(diagnostic); + } + } + + return filtered.ToImmutableOrderedBy(static d => d.Span.AbsoluteIndex); } public void AddSourceMappingFor(IntermediateNode node) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorDiagnosticDescriptor.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorDiagnosticDescriptor.cs index 865a27fb97f..e9ba33c49ee 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorDiagnosticDescriptor.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorDiagnosticDescriptor.cs @@ -43,6 +43,7 @@ public RazorDiagnosticDescriptor(string id, string messageFormat, RazorDiagnosti WarningLevel = warningLevel; } - private string DebuggerToString() - => $"""Error "{Id}" (level {WarningLevel}): "{MessageFormat}"""; -} + private string DebuggerToString() => $""" + Error "{Id}" (level {WarningLevel}): "{MessageFormat}" + """; +} \ No newline at end of file