Skip to content

Commit

Permalink
Add Enumerable.Reverse(this T[]) polyfill (#75104)
Browse files Browse the repository at this point in the history
* Add `Enumerable.Reverse(this T[])` polyfill

* Remove the extension method in .NET 10

Keeping it as non-extension for binary compatibility.
  • Loading branch information
jjonescz authored Sep 19, 2024
1 parent 4d28028 commit 9eb2f8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,13 @@ public static bool SequenceEqual<T>(this IEnumerable<T>? first, IEnumerable<T>?
}
}

// https://github.com/dotnet/runtime/issues/107723
#if NET10_0_OR_GREATER
public static IEnumerable<T> Reverse<T>(T[] source) => Enumerable.Reverse(source);
#else
public static IEnumerable<T> Reverse<T>(this T[] source) => Enumerable.Reverse(source);
#endif

#if NETSTANDARD

// Copied from https://github.com/dotnet/runtime/blob/main/src/libraries/System.Linq/src/System/Linq/Chunk.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ protected override async Task FixAllAsync(

// Process all nodes to refactor in reverse to ensure nested nodes
// are processed before the outer nodes to refactor.
foreach (var originalNode in Enumerable.Reverse(nodes))
foreach (var originalNode in nodes.Reverse())
{
// Only process nodes fully within a fixAllSpan
if (!fixAllSpans.Any(fixAllSpan => fixAllSpan.Contains(originalNode.Span)))
Expand Down

0 comments on commit 9eb2f8f

Please sign in to comment.