core: Fix IsEmptyOrNull to return true when IsNull (#7338) resolves #7333

This commit is contained in:
Cory 2020-02-26 12:24:36 -06:00 committed by GitHub
parent 427b556869
commit b9b10e4e91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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<T>(this ICollection<T> obj) => obj.Count == 0;
public static bool IsEmptyOrNull<T>(this ICollection<T> 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<T>(this ICollection<T> obj) => obj?.IsEmpty() ?? true;
}
public static class XElementExtension