From 4bc48e20a654ca887c32e6aa863f7f0fcf2303ea Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Mon, 30 Aug 2021 18:07:02 +0200 Subject: [PATCH] reverted Sum Method back to previous behavior (returning Null if the source was empty) --- VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs b/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs index 72ca833465..20e6d1aabb 100644 --- a/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs +++ b/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs @@ -159,9 +159,9 @@ namespace TUGraz.VectoCommon.Utils public static T Sum<T>(this IEnumerable<T> values) where T : SIBase<T> => values.Sum(x => x); - public static TResult Sum<T, TResult>(this IEnumerable<T> values, Func<T, TResult> selector) - where TResult : SIBase<TResult> => - values.Sum(value => selector(value).Value()).SI<TResult>(); + public static TResult Sum<TU, TResult>(this IEnumerable<TU> values, Func<TU, TResult> selector) + where TResult : SIBase<TResult> => + values.Select(selector).DefaultIfEmpty().Aggregate((sum, current) => sum + current); public static T Average<T>(this IEnumerable<T> values) where T : SIBase<T> => values.Average(v => v.Value()).SI<T>(); -- GitLab