Skip to content

Commit

Permalink
Use updated ArgumentNullException call
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Nov 15, 2023
1 parent 48c1f11 commit b7b45fc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/DynamicData/Aggregation/AvgEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ public static IObservable<float> Avg<T>(this IObservable<IChangeSet<T>> source,

private static IObservable<TResult> AvgCalc<TObject, TValue, TResult>(this IObservable<IAggregateChangeSet<TObject>> source, Func<TObject, TValue> valueSelector, TResult fallbackValue, Func<Avg<TValue>, TValue, Avg<TValue>> addAction, Func<Avg<TValue>, TValue, Avg<TValue>> removeAction, Func<Avg<TValue>, TResult> resultAction)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(valueSelector);
ArgumentNullException.ThrowIfNull(addAction);
ArgumentNullException.ThrowIfNull(removeAction);
ArgumentNullException.ThrowIfNull(resultAction);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -433,6 +440,7 @@ private static IObservable<TResult> AvgCalc<TObject, TValue, TResult>(this IObse
{
throw new ArgumentNullException(nameof(resultAction));
}
#endif

return source.Scan(default(Avg<TValue>), (state, changes) =>
changes.Aggregate(state, (current, aggregateItem) =>
Expand Down
13 changes: 13 additions & 0 deletions src/DynamicData/Aggregation/MaxEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public static IObservable<TResult> Minimum<TObject, TKey, TResult>(this IObserva
private static IObservable<TResult> Calculate<TObject, TResult>(this IObservable<ChangesAndCollection<TObject>> source, Func<TObject, TResult> valueSelector, MaxOrMin maxOrMin, TResult emptyValue = default)
where TResult : struct, IComparable<TResult>
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -92,6 +96,7 @@ private static IObservable<TResult> Calculate<TObject, TResult>(this IObservable
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Scan(
default(TResult?),
Expand Down Expand Up @@ -154,10 +159,14 @@ private static IObservable<ChangesAndCollection<TObject>> ToChangesAndCollection
where TObject : notnull
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

return source.Publish(
shared =>
Expand All @@ -171,10 +180,14 @@ private static IObservable<ChangesAndCollection<TObject>> ToChangesAndCollection
private static IObservable<ChangesAndCollection<TObject>> ToChangesAndCollection<TObject>(this IObservable<IChangeSet<TObject>> source)
where TObject : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

return source.Publish(
shared =>
Expand Down
8 changes: 8 additions & 0 deletions src/DynamicData/Aggregation/StdDevEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ public static IObservable<decimal> StdDev<T>(this IObservable<IAggregateChangeSe

private static IObservable<TResult> StdDevCalc<TObject, TValue, TResult>(this IObservable<IAggregateChangeSet<TObject>> source, Func<TObject, TValue> valueSelector, TResult fallbackValue, Func<StdDev<TValue>, TValue, StdDev<TValue>> addAction, Func<StdDev<TValue>, TValue, StdDev<TValue>> removeAction, Func<StdDev<TValue>, TResult> resultAction)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(valueSelector);
ArgumentNullException.ThrowIfNull(addAction);
ArgumentNullException.ThrowIfNull(removeAction);
ArgumentNullException.ThrowIfNull(resultAction);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -210,6 +217,7 @@ private static IObservable<TResult> StdDevCalc<TObject, TValue, TResult>(this IO
{
throw new ArgumentNullException(nameof(resultAction));
}
#endif

return source.Scan(default(StdDev<TValue>), (state, changes) =>
changes.Aggregate(state, (current, aggregateItem) =>
Expand Down
54 changes: 54 additions & 0 deletions src/DynamicData/Aggregation/SumEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public static IObservable<float> Sum<T>(this IObservable<IChangeSet<T>> source,
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<int> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, int> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -249,6 +254,7 @@ public static IObservable<int> Sum<T>(this IObservable<IAggregateChangeSet<T>> s
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0, valueSelector, (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -271,6 +277,11 @@ public static IObservable<int> Sum<T>(this IObservable<IAggregateChangeSet<T>> s
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<long> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, long> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -280,6 +291,7 @@ public static IObservable<long> Sum<T>(this IObservable<IAggregateChangeSet<T>>
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0, valueSelector, (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -293,6 +305,11 @@ public static IObservable<long> Sum<T>(this IObservable<IAggregateChangeSet<T>>
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<long> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, long?> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -302,6 +319,7 @@ public static IObservable<long> Sum<T>(this IObservable<IAggregateChangeSet<T>>
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0L, t => valueSelector(t).ValueOr(0), (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -315,6 +333,11 @@ public static IObservable<long> Sum<T>(this IObservable<IAggregateChangeSet<T>>
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<double> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, double> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -324,6 +347,7 @@ public static IObservable<double> Sum<T>(this IObservable<IAggregateChangeSet<T>
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0, valueSelector, (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -337,6 +361,11 @@ public static IObservable<double> Sum<T>(this IObservable<IAggregateChangeSet<T>
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<double> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, double?> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -346,6 +375,7 @@ public static IObservable<double> Sum<T>(this IObservable<IAggregateChangeSet<T>
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0D, t => valueSelector(t).ValueOr(0), (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -359,6 +389,11 @@ public static IObservable<double> Sum<T>(this IObservable<IAggregateChangeSet<T>
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<decimal> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, decimal> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -368,6 +403,7 @@ public static IObservable<decimal> Sum<T>(this IObservable<IAggregateChangeSet<T
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0, valueSelector, (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -381,6 +417,11 @@ public static IObservable<decimal> Sum<T>(this IObservable<IAggregateChangeSet<T
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<decimal> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, decimal?> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -390,6 +431,7 @@ public static IObservable<decimal> Sum<T>(this IObservable<IAggregateChangeSet<T
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0M, t => valueSelector(t).ValueOr(0), (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -403,6 +445,11 @@ public static IObservable<decimal> Sum<T>(this IObservable<IAggregateChangeSet<T
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<float> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, float> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -412,6 +459,7 @@ public static IObservable<float> Sum<T>(this IObservable<IAggregateChangeSet<T>>
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0, valueSelector, (current, value) => current + value, (current, value) => current - value);
}
Expand All @@ -425,6 +473,11 @@ public static IObservable<float> Sum<T>(this IObservable<IAggregateChangeSet<T>>
/// <returns>An observable which emits the summed value.</returns>
public static IObservable<float> Sum<T>(this IObservable<IAggregateChangeSet<T>> source, Func<T, float?> valueSelector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);

ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -434,6 +487,7 @@ public static IObservable<float> Sum<T>(this IObservable<IAggregateChangeSet<T>>
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

return source.Accumulate(0F, t => valueSelector(t).ValueOr(0), (current, value) => current + value, (current, value) => current - value);
}
Expand Down

0 comments on commit b7b45fc

Please sign in to comment.