Code Clean up: Use Pattern Matching (#5838)
Co-authored-by: Cody Robibero <cody@robibe.ro> Co-authored-by: Patrick Barron <18354464+barronpm@users.noreply.github.com>
This commit is contained in:
parent
18d799b22a
commit
f2c10471bf
|
@ -29,9 +29,7 @@ namespace Emby.Server.Implementations.Images
|
|||
{
|
||||
var subItem = i.Item2;
|
||||
|
||||
var episode = subItem as Episode;
|
||||
|
||||
if (episode != null)
|
||||
if (subItem is Episode episode)
|
||||
{
|
||||
var series = episode.Series;
|
||||
if (series != null && series.HasImage(ImageType.Primary))
|
||||
|
|
|
@ -100,8 +100,7 @@ namespace Emby.Server.Implementations.Library
|
|||
|
||||
public List<BaseItem> GetInstantMixFromItem(BaseItem item, User user, DtoOptions dtoOptions)
|
||||
{
|
||||
var genre = item as MusicGenre;
|
||||
if (genre != null)
|
||||
if (item is MusicGenre genre)
|
||||
{
|
||||
return GetInstantMixFromGenreIds(new[] { item.Id }, user, dtoOptions);
|
||||
}
|
||||
|
|
|
@ -348,9 +348,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||
{
|
||||
var trigger = (ITaskTrigger)sender;
|
||||
|
||||
var configurableTask = ScheduledTask as IConfigurableScheduledTask;
|
||||
|
||||
if (configurableTask != null && !configurableTask.IsEnabled)
|
||||
if (ScheduledTask is IConfigurableScheduledTask configurableTask && !configurableTask.IsEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -43,9 +43,7 @@ namespace Emby.Server.Implementations.TV
|
|||
string presentationUniqueKey = null;
|
||||
if (!string.IsNullOrEmpty(request.SeriesId))
|
||||
{
|
||||
var series = _libraryManager.GetItemById(request.SeriesId) as Series;
|
||||
|
||||
if (series != null)
|
||||
if (_libraryManager.GetItemById(request.SeriesId) is Series series)
|
||||
{
|
||||
presentationUniqueKey = GetUniqueSeriesKey(series);
|
||||
}
|
||||
|
@ -95,9 +93,7 @@ namespace Emby.Server.Implementations.TV
|
|||
int? limit = null;
|
||||
if (!string.IsNullOrEmpty(request.SeriesId))
|
||||
{
|
||||
var series = _libraryManager.GetItemById(request.SeriesId) as Series;
|
||||
|
||||
if (series != null)
|
||||
if (_libraryManager.GetItemById(request.SeriesId) is Series series)
|
||||
{
|
||||
presentationUniqueKey = GetUniqueSeriesKey(series);
|
||||
limit = 1;
|
||||
|
|
|
@ -354,9 +354,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
if (result.Count == 0)
|
||||
{
|
||||
var folder = LibraryManager.FindByPath(path, true) as Folder;
|
||||
|
||||
if (folder != null)
|
||||
if (LibraryManager.FindByPath(path, true) is Folder folder)
|
||||
{
|
||||
result.Add(folder);
|
||||
}
|
||||
|
|
|
@ -217,8 +217,7 @@ namespace MediaBrowser.Controller.Entities.Movies
|
|||
|
||||
private IEnumerable<BaseItem> FlattenItems(BaseItem item, List<Guid> expandedFolders)
|
||||
{
|
||||
var boxset = item as BoxSet;
|
||||
if (boxset != null)
|
||||
if (item is BoxSet boxset)
|
||||
{
|
||||
if (!expandedFolders.Contains(item.Id))
|
||||
{
|
||||
|
|
|
@ -24,8 +24,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
var parents = GetParents();
|
||||
foreach (var parent in parents)
|
||||
{
|
||||
var photoAlbum = parent as PhotoAlbum;
|
||||
if (photoAlbum != null)
|
||||
if (parent is PhotoAlbum photoAlbum)
|
||||
{
|
||||
return photoAlbum;
|
||||
}
|
||||
|
|
|
@ -316,20 +316,13 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var skipItem = false;
|
||||
|
||||
var episode = item as Episode;
|
||||
|
||||
if (episode != null
|
||||
bool skipItem = item is Episode episode
|
||||
&& refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh
|
||||
&& !refreshOptions.ReplaceAllMetadata
|
||||
&& episode.IsMissingEpisode
|
||||
&& episode.LocationType == LocationType.Virtual
|
||||
&& episode.PremiereDate.HasValue
|
||||
&& (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30)
|
||||
{
|
||||
skipItem = true;
|
||||
}
|
||||
&& (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30;
|
||||
|
||||
if (!skipItem)
|
||||
{
|
||||
|
|
|
@ -14,8 +14,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
ContainingFolderPath = item.ContainingFolderPath;
|
||||
IsInMixedFolder = item.IsInMixedFolder;
|
||||
|
||||
var video = item as Video;
|
||||
if (video != null)
|
||||
if (item is Video video)
|
||||
{
|
||||
VideoType = video.VideoType;
|
||||
IsPlaceHolder = video.IsPlaceHolder;
|
||||
|
|
|
@ -468,8 +468,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
|
|||
{
|
||||
var val = reader.ReadElementContentAsString();
|
||||
|
||||
var hasDisplayOrder = item as IHasDisplayOrder;
|
||||
if (hasDisplayOrder != null)
|
||||
if (item is IHasDisplayOrder hasDisplayOrder)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(val))
|
||||
{
|
||||
|
|
|
@ -296,8 +296,7 @@ namespace MediaBrowser.LocalMetadata.Savers
|
|||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
var hasDisplayOrder = item as IHasDisplayOrder;
|
||||
if (hasDisplayOrder != null && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
|
||||
if (item is IHasDisplayOrder hasDisplayOrder && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
|
||||
{
|
||||
writer.WriteElementString("DisplayOrder", hasDisplayOrder.DisplayOrder);
|
||||
}
|
||||
|
@ -312,8 +311,7 @@ namespace MediaBrowser.LocalMetadata.Savers
|
|||
writer.WriteElementString("ProductionYear", item.ProductionYear.Value.ToString(_usCulture));
|
||||
}
|
||||
|
||||
var hasAspectRatio = item as IHasAspectRatio;
|
||||
if (hasAspectRatio != null)
|
||||
if (item is IHasAspectRatio hasAspectRatio)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
|
||||
{
|
||||
|
|
|
@ -61,33 +61,25 @@ namespace MediaBrowser.MediaEncoding.BdInfo
|
|||
|
||||
foreach (var stream in playlist.SortedStreams)
|
||||
{
|
||||
var videoStream = stream as TSVideoStream;
|
||||
|
||||
if (videoStream != null)
|
||||
if (stream is TSVideoStream videoStream)
|
||||
{
|
||||
AddVideoStream(mediaStreams, videoStream);
|
||||
continue;
|
||||
}
|
||||
|
||||
var audioStream = stream as TSAudioStream;
|
||||
|
||||
if (audioStream != null)
|
||||
if (stream is TSAudioStream audioStream)
|
||||
{
|
||||
AddAudioStream(mediaStreams, audioStream);
|
||||
continue;
|
||||
}
|
||||
|
||||
var textStream = stream as TSTextStream;
|
||||
|
||||
if (textStream != null)
|
||||
if (stream is TSTextStream textStream)
|
||||
{
|
||||
AddSubtitleStream(mediaStreams, textStream);
|
||||
continue;
|
||||
}
|
||||
|
||||
var graphicsStream = stream as TSGraphicsStream;
|
||||
|
||||
if (graphicsStream != null)
|
||||
if (stream is TSGraphicsStream graphicsStream)
|
||||
{
|
||||
AddSubtitleStream(mediaStreams, graphicsStream);
|
||||
}
|
||||
|
|
|
@ -281,8 +281,7 @@ namespace MediaBrowser.Providers.Manager
|
|||
return true;
|
||||
}
|
||||
|
||||
var folder = item as Folder;
|
||||
if (folder != null)
|
||||
if (item is Folder folder)
|
||||
{
|
||||
return folder.SupportsDateLastMediaAdded || folder.SupportsCumulativeRunTimeTicks;
|
||||
}
|
||||
|
@ -336,8 +335,7 @@ namespace MediaBrowser.Providers.Manager
|
|||
|
||||
private ItemUpdateType UpdateCumulativeRunTimeTicks(TItemType item, IList<BaseItem> children)
|
||||
{
|
||||
var folder = item as Folder;
|
||||
if (folder != null && folder.SupportsCumulativeRunTimeTicks)
|
||||
if (item is Folder folder && folder.SupportsCumulativeRunTimeTicks)
|
||||
{
|
||||
long ticks = 0;
|
||||
|
||||
|
|
|
@ -137,9 +137,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
return false;
|
||||
}
|
||||
|
||||
var audio = item as Audio;
|
||||
|
||||
return audio != null;
|
||||
return item is Audio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,9 +172,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
SubtitleFetcherOrder = subtitleFetcherOrder
|
||||
};
|
||||
|
||||
var episode = video as Episode;
|
||||
|
||||
if (episode != null)
|
||||
if (video is Episode episode)
|
||||
{
|
||||
request.IndexNumberEnd = episode.IndexNumberEnd;
|
||||
request.SeriesName = episode.SeriesName;
|
||||
|
|
|
@ -154,9 +154,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
return false;
|
||||
}
|
||||
|
||||
var video = item as Video;
|
||||
|
||||
if (video != null && !video.IsPlaceHolder && video.IsCompleteMedia)
|
||||
if (item is Video video && !video.IsPlaceHolder && video.IsCompleteMedia)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user