Use LINQ MaxBy() and MinBy()

Proprietary

Replace collection.OrderByDescending(selector).First() with collection.MaxBy(selector) and collection.OrderBy(selector).First() with collection.MinBy(selector). Also handles .Last() variants (OrderBy().Last() → MaxBy, OrderByDescending().Last() → MinBy). Note: MinBy/MaxBy return default for empty reference-type sequences instead of throwing. Available since .NET 6.

OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net6.UseLinqMaxMinBy
mod run . --recipe=OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net6.UseLinqMaxMinBy

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.