LINQ code quality
ProprietaryOptimize LINQ method calls for better readability and performance.
OpenRewrite. Recipes. CSharp. CodeQuality. Linq. LinqCodeQualitymod run . --recipe= OpenRewrite. Recipes. CSharp. CodeQuality. Linq. LinqCodeQualityInstall it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Optimize LINQ Where().Any()
- Optimize LINQ Where().Count()
- Optimize LINQ Where().First()
- Optimize LINQ Where().FirstOrDefault()
- Optimize LINQ Where().Single()
- Optimize LINQ Where().SingleOrDefault()
- Optimize LINQ Where().Last()
- Optimize LINQ Where().LastOrDefault()
- Optimize LINQ Where().LongCount()
- Optimize LINQ Select().Max()
- Optimize LINQ Select().Min()
- Optimize LINQ Select().Sum()
- Optimize LINQ Select().Average()
- Use ThenBy instead of second OrderBy
- Use OrderBy().ThenByDescending()
- Use OrderByDescending().ThenByDescending()
- Use Order() instead of OrderBy() with identity
- Remove useless OrderBy call
- Use Cast<T>() instead of Select with cast
- Combine LINQ methods
- Use Where before OrderBy
- Use Any() instead of Count() > 0
- Find Count() comparison that could be optimized