C#: Use the first best location from the list of locations.

This commit is contained in:
Michael Nebel
2024-06-26 11:04:38 +02:00
parent d18915a1e4
commit e258d9fa74

View File

@@ -76,7 +76,7 @@ namespace Semmle.Extraction
/// lexicographically smaller filepath and span is considered better.
/// </summary>
public static Location? BestOrDefault(this IEnumerable<Location> locations) =>
locations.Any() ? locations.Aggregate((best, loc) => BetterThan(best, loc) ? best : loc) : null;
locations.Any() ? locations.Aggregate((best, loc) => BetterThan(loc, best) ? loc : best) : null;
public static Location Best(this IEnumerable<Location> locations) =>
locations.BestOrDefault() ?? throw new ArgumentException("No location found.");