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>
pull/5987/head
BaronGreenback 4 years ago committed by GitHub
parent 18d799b22a
commit f2c10471bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,9 +29,7 @@ namespace Emby.Server.Implementations.Images
{ {
var subItem = i.Item2; var subItem = i.Item2;
var episode = subItem as Episode; if (subItem is Episode episode)
if (episode != null)
{ {
var series = episode.Series; var series = episode.Series;
if (series != null && series.HasImage(ImageType.Primary)) 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) public List<BaseItem> GetInstantMixFromItem(BaseItem item, User user, DtoOptions dtoOptions)
{ {
var genre = item as MusicGenre; if (item is MusicGenre genre)
if (genre != null)
{ {
return GetInstantMixFromGenreIds(new[] { item.Id }, user, dtoOptions); return GetInstantMixFromGenreIds(new[] { item.Id }, user, dtoOptions);
} }

@ -348,9 +348,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
{ {
var trigger = (ITaskTrigger)sender; var trigger = (ITaskTrigger)sender;
var configurableTask = ScheduledTask as IConfigurableScheduledTask; if (ScheduledTask is IConfigurableScheduledTask configurableTask && !configurableTask.IsEnabled)
if (configurableTask != null && !configurableTask.IsEnabled)
{ {
return; return;
} }

@ -43,9 +43,7 @@ namespace Emby.Server.Implementations.TV
string presentationUniqueKey = null; string presentationUniqueKey = null;
if (!string.IsNullOrEmpty(request.SeriesId)) if (!string.IsNullOrEmpty(request.SeriesId))
{ {
var series = _libraryManager.GetItemById(request.SeriesId) as Series; if (_libraryManager.GetItemById(request.SeriesId) is Series series)
if (series != null)
{ {
presentationUniqueKey = GetUniqueSeriesKey(series); presentationUniqueKey = GetUniqueSeriesKey(series);
} }
@ -95,9 +93,7 @@ namespace Emby.Server.Implementations.TV
int? limit = null; int? limit = null;
if (!string.IsNullOrEmpty(request.SeriesId)) if (!string.IsNullOrEmpty(request.SeriesId))
{ {
var series = _libraryManager.GetItemById(request.SeriesId) as Series; if (_libraryManager.GetItemById(request.SeriesId) is Series series)
if (series != null)
{ {
presentationUniqueKey = GetUniqueSeriesKey(series); presentationUniqueKey = GetUniqueSeriesKey(series);
limit = 1; limit = 1;

@ -354,9 +354,7 @@ namespace MediaBrowser.Controller.Entities
if (result.Count == 0) if (result.Count == 0)
{ {
var folder = LibraryManager.FindByPath(path, true) as Folder; if (LibraryManager.FindByPath(path, true) is Folder folder)
if (folder != null)
{ {
result.Add(folder); result.Add(folder);
} }

@ -217,8 +217,7 @@ namespace MediaBrowser.Controller.Entities.Movies
private IEnumerable<BaseItem> FlattenItems(BaseItem item, List<Guid> expandedFolders) private IEnumerable<BaseItem> FlattenItems(BaseItem item, List<Guid> expandedFolders)
{ {
var boxset = item as BoxSet; if (item is BoxSet boxset)
if (boxset != null)
{ {
if (!expandedFolders.Contains(item.Id)) if (!expandedFolders.Contains(item.Id))
{ {

@ -24,8 +24,7 @@ namespace MediaBrowser.Controller.Entities
var parents = GetParents(); var parents = GetParents();
foreach (var parent in parents) foreach (var parent in parents)
{ {
var photoAlbum = parent as PhotoAlbum; if (parent is PhotoAlbum photoAlbum)
if (photoAlbum != null)
{ {
return photoAlbum; return photoAlbum;
} }

@ -316,20 +316,13 @@ namespace MediaBrowser.Controller.Entities.TV
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var skipItem = false; bool skipItem = item is Episode episode
var episode = item as Episode;
if (episode != null
&& refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh && refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh
&& !refreshOptions.ReplaceAllMetadata && !refreshOptions.ReplaceAllMetadata
&& episode.IsMissingEpisode && episode.IsMissingEpisode
&& episode.LocationType == LocationType.Virtual && episode.LocationType == LocationType.Virtual
&& episode.PremiereDate.HasValue && episode.PremiereDate.HasValue
&& (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30) && (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30;
{
skipItem = true;
}
if (!skipItem) if (!skipItem)
{ {

@ -14,8 +14,7 @@ namespace MediaBrowser.Controller.Providers
ContainingFolderPath = item.ContainingFolderPath; ContainingFolderPath = item.ContainingFolderPath;
IsInMixedFolder = item.IsInMixedFolder; IsInMixedFolder = item.IsInMixedFolder;
var video = item as Video; if (item is Video video)
if (video != null)
{ {
VideoType = video.VideoType; VideoType = video.VideoType;
IsPlaceHolder = video.IsPlaceHolder; IsPlaceHolder = video.IsPlaceHolder;

@ -468,8 +468,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
{ {
var val = reader.ReadElementContentAsString(); var val = reader.ReadElementContentAsString();
var hasDisplayOrder = item as IHasDisplayOrder; if (item is IHasDisplayOrder hasDisplayOrder)
if (hasDisplayOrder != null)
{ {
if (!string.IsNullOrWhiteSpace(val)) if (!string.IsNullOrWhiteSpace(val))
{ {

@ -296,8 +296,7 @@ namespace MediaBrowser.LocalMetadata.Savers
writer.WriteEndElement(); writer.WriteEndElement();
} }
var hasDisplayOrder = item as IHasDisplayOrder; if (item is IHasDisplayOrder hasDisplayOrder && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
if (hasDisplayOrder != null && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
{ {
writer.WriteElementString("DisplayOrder", hasDisplayOrder.DisplayOrder); writer.WriteElementString("DisplayOrder", hasDisplayOrder.DisplayOrder);
} }
@ -312,8 +311,7 @@ namespace MediaBrowser.LocalMetadata.Savers
writer.WriteElementString("ProductionYear", item.ProductionYear.Value.ToString(_usCulture)); writer.WriteElementString("ProductionYear", item.ProductionYear.Value.ToString(_usCulture));
} }
var hasAspectRatio = item as IHasAspectRatio; if (item is IHasAspectRatio hasAspectRatio)
if (hasAspectRatio != null)
{ {
if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio)) if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
{ {

@ -61,33 +61,25 @@ namespace MediaBrowser.MediaEncoding.BdInfo
foreach (var stream in playlist.SortedStreams) foreach (var stream in playlist.SortedStreams)
{ {
var videoStream = stream as TSVideoStream; if (stream is TSVideoStream videoStream)
if (videoStream != null)
{ {
AddVideoStream(mediaStreams, videoStream); AddVideoStream(mediaStreams, videoStream);
continue; continue;
} }
var audioStream = stream as TSAudioStream; if (stream is TSAudioStream audioStream)
if (audioStream != null)
{ {
AddAudioStream(mediaStreams, audioStream); AddAudioStream(mediaStreams, audioStream);
continue; continue;
} }
var textStream = stream as TSTextStream; if (stream is TSTextStream textStream)
if (textStream != null)
{ {
AddSubtitleStream(mediaStreams, textStream); AddSubtitleStream(mediaStreams, textStream);
continue; continue;
} }
var graphicsStream = stream as TSGraphicsStream; if (stream is TSGraphicsStream graphicsStream)
if (graphicsStream != null)
{ {
AddSubtitleStream(mediaStreams, graphicsStream); AddSubtitleStream(mediaStreams, graphicsStream);
} }

@ -281,8 +281,7 @@ namespace MediaBrowser.Providers.Manager
return true; return true;
} }
var folder = item as Folder; if (item is Folder folder)
if (folder != null)
{ {
return folder.SupportsDateLastMediaAdded || folder.SupportsCumulativeRunTimeTicks; return folder.SupportsDateLastMediaAdded || folder.SupportsCumulativeRunTimeTicks;
} }
@ -336,8 +335,7 @@ namespace MediaBrowser.Providers.Manager
private ItemUpdateType UpdateCumulativeRunTimeTicks(TItemType item, IList<BaseItem> children) private ItemUpdateType UpdateCumulativeRunTimeTicks(TItemType item, IList<BaseItem> children)
{ {
var folder = item as Folder; if (item is Folder folder && folder.SupportsCumulativeRunTimeTicks)
if (folder != null && folder.SupportsCumulativeRunTimeTicks)
{ {
long ticks = 0; long ticks = 0;

@ -137,9 +137,7 @@ namespace MediaBrowser.Providers.MediaInfo
return false; return false;
} }
var audio = item as Audio; return item is Audio;
return audio != null;
} }
} }
} }

@ -172,9 +172,7 @@ namespace MediaBrowser.Providers.MediaInfo
SubtitleFetcherOrder = subtitleFetcherOrder SubtitleFetcherOrder = subtitleFetcherOrder
}; };
var episode = video as Episode; if (video is Episode episode)
if (episode != null)
{ {
request.IndexNumberEnd = episode.IndexNumberEnd; request.IndexNumberEnd = episode.IndexNumberEnd;
request.SeriesName = episode.SeriesName; request.SeriesName = episode.SeriesName;

@ -154,9 +154,7 @@ namespace MediaBrowser.Providers.MediaInfo
return false; return false;
} }
var video = item as Video; if (item is Video video && !video.IsPlaceHolder && video.IsCompleteMedia)
if (video != null && !video.IsPlaceHolder && video.IsCompleteMedia)
{ {
return true; return true;
} }

Loading…
Cancel
Save