// Ignore Spelling: Linq using System; using System.Collections.Generic; using System.Linq; namespace AsbCloudInfrastructure; public static class LinqExtensions { public static TProp? MaxOrDefault(this IEnumerable enumerable, Func getter) where TProp : struct { var value = MaxByOrDefault(enumerable, getter); if (value is null) return null; return getter(value); } public static TObj? MaxByOrDefault(this IEnumerable enumerable, Func getter) { return enumerable.OrderByDescending(getter).FirstOrDefault(); } public static TProp? MinOrDefault(this IEnumerable enumerable, Func getter) where TProp : struct { var value = MinByOrDefault(enumerable, getter); if (value is null) return null; return getter(value); } public static TObj? MinByOrDefault(this IEnumerable enumerable, Func getter) { return enumerable.OrderBy(getter).FirstOrDefault(); } }