From b9b10e4e91391481e64f2dc51118b67fad3d5e3b Mon Sep 17 00:00:00 2001 From: Cory Date: Wed, 26 Feb 2020 12:24:36 -0600 Subject: [PATCH] core: Fix IsEmptyOrNull to return true when IsNull (#7338) resolves #7333 --- src/Jackett.Common/Utils/Extensions.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Jackett.Common/Utils/Extensions.cs b/src/Jackett.Common/Utils/Extensions.cs index 813261f86..0de08f589 100644 --- a/src/Jackett.Common/Utils/Extensions.cs +++ b/src/Jackett.Common/Utils/Extensions.cs @@ -64,8 +64,11 @@ namespace Jackett.Common.Utils // IEnumerable class above already does this. All ICollection are IEnumerable, so favor IEnumerable? public static bool IsEmpty(this ICollection obj) => obj.Count == 0; - - public static bool IsEmptyOrNull(this ICollection obj) => obj?.IsEmpty() == true; + // obj == null || obj.IsEmpty() causes VS to suggest merging sequential checks + // the result is obj?.IsEmpty() == true which returns false when null + // Other options are obj?.IsEmpty() == true || obj == null Or (obj?.IsEmpty()).GetValueOrDefault(true) + // All three options remove the suggestion and give the intended result of this function + public static bool IsEmptyOrNull(this ICollection obj) => obj?.IsEmpty() ?? true; } public static class XElementExtension