Browse Source

Use pattern matching for null checks (#13793)

Fix the few that slipped through
Bond-009 2 months ago
parent
commit
e9729a536f

+ 1 - 1
Jellyfin.Api/Controllers/DynamicHlsController.cs

@@ -1753,7 +1753,7 @@ public class DynamicHlsController : BaseJellyfinApiController
 
         if (channels.HasValue
             && (channels.Value != 2
-                || (state.AudioStream?.Channels != null && !useDownMixAlgorithm)))
+                || (state.AudioStream?.Channels is not null && !useDownMixAlgorithm)))
         {
             args += " -ac " + channels.Value;
         }

+ 1 - 1
MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs

@@ -5621,7 +5621,7 @@ namespace MediaBrowser.Controller.MediaEncoding
             var doDeintH2645 = doDeintH264 || doDeintHevc;
             var doOclTonemap = IsHwTonemapAvailable(state, options);
 
-            var hasSubs = state.SubtitleStream != null && ShouldEncodeSubtitle(state);
+            var hasSubs = state.SubtitleStream is not null && ShouldEncodeSubtitle(state);
             var hasTextSubs = hasSubs && state.SubtitleStream.IsTextSubtitleStream;
             var hasGraphicalSubs = hasSubs && !state.SubtitleStream.IsTextSubtitleStream;
             var hasAssSubs = hasSubs

+ 2 - 2
MediaBrowser.Model/Extensions/ContainerHelper.cs

@@ -21,7 +21,7 @@ public static class ContainerHelper
     public static bool ContainsContainer(string? profileContainers, string? inputContainer)
     {
         var isNegativeList = false;
-        if (profileContainers != null && profileContainers.StartsWith('-'))
+        if (profileContainers is not null && profileContainers.StartsWith('-'))
         {
             isNegativeList = true;
             profileContainers = profileContainers[1..];
@@ -42,7 +42,7 @@ public static class ContainerHelper
     public static bool ContainsContainer(string? profileContainers, ReadOnlySpan<char> inputContainer)
     {
         var isNegativeList = false;
-        if (profileContainers != null && profileContainers.StartsWith('-'))
+        if (profileContainers is not null && profileContainers.StartsWith('-'))
         {
             isNegativeList = true;
             profileContainers = profileContainers[1..];

+ 1 - 1
MediaBrowser.Providers/TV/SeriesMetadataService.cs

@@ -55,7 +55,7 @@ namespace MediaBrowser.Providers.TV
 
                 foreach (var season in seasons)
                 {
-                    var hasUpdate = refreshOptions != null && season.BeforeMetadataRefresh(refreshOptions.ReplaceAllMetadata);
+                    var hasUpdate = refreshOptions is not null && season.BeforeMetadataRefresh(refreshOptions.ReplaceAllMetadata);
                     if (hasUpdate)
                     {
                         await season.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);

+ 1 - 1
MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs

@@ -95,7 +95,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
                         originalTitle.Append(" / ").Append(additionalEpisode.Item.OriginalTitle);
                     }
 
-                    if (additionalEpisode.Item.IndexNumber != null)
+                    if (additionalEpisode.Item.IndexNumber is not null)
                     {
                         item.Item.IndexNumberEnd = Math.Max((int)additionalEpisode.Item.IndexNumber, item.Item.IndexNumberEnd ?? (int)additionalEpisode.Item.IndexNumber);
                     }

+ 2 - 2
MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs

@@ -1020,12 +1020,12 @@ namespace MediaBrowser.XbmcMetadata.Savers
 
         protected static string SortNameOrName(BaseItem item)
         {
-            if (item == null)
+            if (item is null)
             {
                 return string.Empty;
             }
 
-            if (item.SortName != null)
+            if (item.SortName is not null)
             {
                 string trimmed = item.SortName.Trim();
                 if (trimmed.Length > 0)

+ 2 - 2
tests/Jellyfin.Api.Tests/Controllers/UserControllerTests.cs

@@ -87,7 +87,7 @@ public class UserControllerTests
         Assert.Contains(
             Validate(userPolicy), v =>
                 v.MemberNames.Contains("PasswordResetProviderId") &&
-                v.ErrorMessage != null &&
+                v.ErrorMessage is not null &&
                 v.ErrorMessage.Contains("required", StringComparison.CurrentCultureIgnoreCase));
     }
 
@@ -105,7 +105,7 @@ public class UserControllerTests
 
         Assert.Contains(Validate(userPolicy), v =>
             v.MemberNames.Contains("AuthenticationProviderId") &&
-            v.ErrorMessage != null &&
+            v.ErrorMessage is not null &&
             v.ErrorMessage.Contains("required", StringComparison.CurrentCultureIgnoreCase));
     }
 

+ 2 - 2
tests/Jellyfin.Model.Tests/Dlna/StreamInfoTests.cs

@@ -31,7 +31,7 @@ public class StreamInfoTests
     /// <returns>An <see cref="Array"/> of <see cref="Type"/>.</returns>
     private static object? RandomArray(Random random, Type? elementType)
     {
-        if (elementType == null)
+        if (elementType is null)
         {
             return null;
         }
@@ -148,7 +148,7 @@ public class StreamInfoTests
 
             var type = property.PropertyType;
             // If nullable, then set it to null, 25% of the time.
-            if (Nullable.GetUnderlyingType(type) != null)
+            if (Nullable.GetUnderlyingType(type) is not null)
             {
                 if (random.Next(0, 4) == 0)
                 {