There are two DTO records:
public record struct DateHour(int Hour, double? Value);
private record struct HourSnapshot(uint TotalSeconds, double? Value);
I have another method which works with enum. I just provide a hand of switch expression for brevity:
HistoryType.LastValueChange => GetTagHourHistory(tagID, scannerName!, dateTime, true)
.OrderBy(hs => hs.TotalSeconds).Aggregate(null,
(lastChange, current) => (lastChange is HourSnapshot hs && hs.Value != current.Value)
? lastChange with { TotalSeconds = current.TotalSeconds, Value = current.Value }
: current,
aggrResult => (aggrResult is not null)
? new DateTime(dateTime.Year, dateTime.Month, dateTime.Day) + TimeSpan.FromSeconds(hs.TotalSeconds)
: null),
What it does is looking through the IEnumerable from GetTagHourHistory method and tries to find the last value change for the tag in a data source.
I get a compiller error which says "try to explicitly define arguments type". As soon as I change the call to Aggregate<DateHour?>
, it fails with error "no overload has three arguments".
According to MSDN there is an overload with resultSelector
predicate:
public static TResult Aggregate<TSource,TAccumulate,TResult> (this System.Collections.Generic.IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate,TSource,TAccumulate> func, Func<TAccumulate,TResult> resultSelector);
It suspect the null seed value for my aggregation, but the only thing to be done, once again, according to MSDN, using explicit type notation is erroneuos.