From eadfc38a6913c8ee4e25fdb92a0955c3d6a4ff8b Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 31 May 2022 15:35:19 -0400 Subject: [PATCH] refactor: Use nullability feat in ExceptNull, DisposeAll fns --- .../Collections/Extensions/EnumerableExtensions.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client/spark_core/Collections/Extensions/EnumerableExtensions.cs b/src/client/spark_core/Collections/Extensions/EnumerableExtensions.cs index 3baac4382..be462dd99 100644 --- a/src/client/spark_core/Collections/Extensions/EnumerableExtensions.cs +++ b/src/client/spark_core/Collections/Extensions/EnumerableExtensions.cs @@ -237,10 +237,11 @@ namespace System.Collections.Generic { yield return ConvertUtils.try_convert(v); } - public static IEnumerable ExceptNull(this IEnumerable source) where T : class { + public static IEnumerable ExceptNull(this IEnumerable source) where T : class { foreach (var v in source) { - if (v != null) + if (v is not null) { yield return v; + } } } @@ -908,9 +909,10 @@ namespace System.Collections.Generic { public static IEnumerable empty_if_null(this IEnumerable? source) => source ?? Enumerable.Empty(); - public static void DisposeAll(this IEnumerable source) { - foreach (IDisposable d in source) - d.Dispose(); + public static void DisposeAll(this IEnumerable source) { + foreach (var d in source) { + d?.Dispose(); + } } public static IEnumerable return_if(bool condition, Func get_value) {