refactor: Use nullability feat in ExceptNull, DisposeAll fns

This commit is contained in:
John Colvin committed 2022-06-01 19:02:41 -04:00
1 parent 098ee36c3a
commit eadfc38a69
1 file changed
+7 -5
@@ -237,10 +237,11 @@ namespace System.Collections.Generic {
yield return ConvertUtils.try_convert<T>(v);
}
public static IEnumerable<T> ExceptNull<T>(this IEnumerable<T> source) where T : class {
public static IEnumerable<T> ExceptNull<T>(this IEnumerable<T?> 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<T> empty_if_null<T>(this IEnumerable<T>? source) =>
source ?? Enumerable.Empty<T>();
public static void DisposeAll(this IEnumerable<IDisposable> source) {
foreach (IDisposable d in source)
d.Dispose();
public static void DisposeAll(this IEnumerable<IDisposable?> source) {
foreach (var d in source) {
d?.Dispose();
}
}
public static IEnumerable<T> return_if<T>(bool condition, Func<T> get_value) {