refactor: Rename Empty/NotEmpty extension methods

pull/201/head
Robert Dailey 2 years ago
parent 61c9dbcbf9
commit fd3d76bc55

@ -39,22 +39,17 @@ public static class CollectionExtensions
return observable.Where(x => x is not null).Select(x => x!); return observable.Where(x => x is not null).Select(x => x!);
} }
public static bool Empty<T>(this ICollection<T>? collection) public static bool IsEmpty<T>(this ICollection<T>? collection)
{ {
return collection is null or {Count: 0}; return collection is null or {Count: 0};
} }
public static bool Empty<T>(this IReadOnlyCollection<T>? collection) public static bool IsEmpty<T>(this IReadOnlyCollection<T>? collection)
{ {
return collection is null or {Count: 0}; return collection is null or {Count: 0};
} }
public static bool NotEmpty<T>(this ICollection<T>? collection) public static bool IsNotEmpty<T>(this ICollection<T>? collection)
{
return collection is {Count: > 0};
}
public static bool NotEmpty<T>(this IReadOnlyCollection<T>? collection)
{ {
return collection is {Count: > 0}; return collection is {Count: > 0};
} }

@ -30,12 +30,12 @@ public class SonarrCapabilityEnforcer
switch (capabilities.SupportsCustomFormats) switch (capabilities.SupportsCustomFormats)
{ {
case true when config.ReleaseProfiles.NotEmpty(): case true when config.ReleaseProfiles.IsNotEmpty():
throw new ServiceIncompatibilityException( throw new ServiceIncompatibilityException(
"Release profiles require Sonarr v3. " + "Release profiles require Sonarr v3. " +
"Please use `custom_formats` instead or use the right version of Sonarr."); "Please use `custom_formats` instead or use the right version of Sonarr.");
case false when config.CustomFormats.NotEmpty(): case false when config.CustomFormats.IsNotEmpty():
throw new ServiceIncompatibilityException( throw new ServiceIncompatibilityException(
"Custom formats require Sonarr v4 or greater. " + "Custom formats require Sonarr v4 or greater. " +
"Please use `release_profiles` instead or use the right version of Sonarr."); "Please use `release_profiles` instead or use the right version of Sonarr.");

@ -12,7 +12,7 @@ public class SonarrConfigurationValidator : AbstractValidator<SonarrConfiguratio
{ {
RuleForEach(x => x.ReleaseProfiles) RuleForEach(x => x.ReleaseProfiles)
.Empty() .Empty()
.When(x => x.CustomFormats.NotEmpty()) .When(x => x.CustomFormats.IsNotEmpty())
.WithMessage("`custom_formats` and `release_profiles` may not be used together"); .WithMessage("`custom_formats` and `release_profiles` may not be used together");
RuleForEach(x => x.ReleaseProfiles).SetValidator(new ReleaseProfileConfigValidator()); RuleForEach(x => x.ReleaseProfiles).SetValidator(new ReleaseProfileConfigValidator());

Loading…
Cancel
Save