diff options
Diffstat (limited to 'MediaBrowser.Controller/Entities/BaseItem.cs')
| -rw-r--r-- | MediaBrowser.Controller/Entities/BaseItem.cs | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 7f5f9f74b..32fe1b3b0 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -494,7 +494,7 @@ namespace MediaBrowser.Controller.Entities { get { - if (_sortName == null) + if (_sortName is null) { if (!string.IsNullOrEmpty(ForcedSortName)) { @@ -658,7 +658,7 @@ namespace MediaBrowser.Controller.Entities } var parent = DisplayParent; - if (parent != null) + if (parent is not null) { return parent.OfficialRatingForComparison; } @@ -679,7 +679,7 @@ namespace MediaBrowser.Controller.Entities } var parent = DisplayParent; - if (parent != null) + if (parent is not null) { return parent.CustomRatingForComparison; } @@ -880,7 +880,7 @@ namespace MediaBrowser.Controller.Entities /// <returns>System.String.</returns> protected virtual string CreateSortName() { - if (Name == null) + if (Name is null) { return null; // some items may not have name filled in properly } @@ -976,7 +976,7 @@ namespace MediaBrowser.Controller.Entities { var parent = GetParent(); - while (parent != null) + while (parent is not null) { yield return parent; @@ -1073,7 +1073,7 @@ namespace MediaBrowser.Controller.Entities { var stream = i.VideoStream; - return stream == null || stream.Width == null ? 0 : stream.Width.Value; + return stream is null || stream.Width is null ? 0 : stream.Width.Value; }) .ToList(); } @@ -1114,7 +1114,7 @@ namespace MediaBrowser.Controller.Entities } var video = item as Video; - if (video != null) + if (video is not null) { info.IsoType = video.IsoType; info.VideoType = video.VideoType; @@ -1153,7 +1153,7 @@ namespace MediaBrowser.Controller.Entities info.SupportsDirectStream = MediaSourceManager.SupportsDirectStream(info.Path, info.Protocol); } - if (video != null && video.VideoType != VideoType.VideoFile) + if (video is not null && video.VideoType != VideoType.VideoFile) { info.SupportsDirectStream = false; } @@ -1330,7 +1330,7 @@ namespace MediaBrowser.Controller.Entities public void SetParent(Folder parent) { - ParentId = parent == null ? Guid.Empty : parent.Id; + ParentId = parent is null ? Guid.Empty : parent.Id; } /// <summary> @@ -1534,7 +1534,7 @@ namespace MediaBrowser.Controller.Entities var maxAllowedRating = user.MaxParentalAgeRating; - if (maxAllowedRating == null) + if (maxAllowedRating is null) { return true; } @@ -1692,7 +1692,7 @@ namespace MediaBrowser.Controller.Entities var itemById = LibraryManager.GetItemById(info.ItemId.Value); - if (itemById != null) + if (itemById is not null) { return itemById; } @@ -1701,7 +1701,7 @@ namespace MediaBrowser.Controller.Entities var item = FindLinkedChild(info); // If still null, log - if (item == null) + if (item is null) { // Don't keep searching over and over info.ItemId = Guid.Empty; @@ -1725,7 +1725,7 @@ namespace MediaBrowser.Controller.Entities var itemByPath = LibraryManager.FindByPath(path, null); - if (itemByPath == null) + if (itemByPath is null) { Logger.LogWarning("Unable to find linked item at path {0}", info.Path); } @@ -1737,7 +1737,7 @@ namespace MediaBrowser.Controller.Entities { var item = LibraryManager.GetItemById(info.LibraryItemId); - if (item == null) + if (item is null) { Logger.LogWarning("Unable to find linked item at path {0}", info.Path); } @@ -1755,10 +1755,7 @@ namespace MediaBrowser.Controller.Entities /// <exception cref="ArgumentNullException">Throws if name is null.</exception> public void AddStudio(string name) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(nameof(name)); - } + ArgumentException.ThrowIfNullOrEmpty(name); var current = Studios; @@ -1791,10 +1788,7 @@ namespace MediaBrowser.Controller.Entities /// <exception cref="ArgumentNullException">Throwns if name is null.</exception> public void AddGenre(string name) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(nameof(name)); - } + ArgumentException.ThrowIfNullOrEmpty(name); var genres = Genres; if (!genres.Contains(name, StringComparison.OrdinalIgnoreCase)) @@ -1892,7 +1886,7 @@ namespace MediaBrowser.Controller.Entities var existingImage = GetImageInfo(image.Type, index); - if (existingImage == null) + if (existingImage is null) { AddImage(image); } @@ -1915,7 +1909,7 @@ namespace MediaBrowser.Controller.Entities var image = GetImageInfo(type, index); - if (image == null) + if (image is null) { AddImage(GetImageInfo(file, type)); } @@ -1942,7 +1936,7 @@ namespace MediaBrowser.Controller.Entities { var info = GetImageInfo(type, index); - if (info == null) + if (info is null) { // Nothing to do return; @@ -2035,7 +2029,7 @@ namespace MediaBrowser.Controller.Entities { var chapter = ItemRepository.GetChapter(this, imageIndex); - if (chapter == null) + if (chapter is null) { return null; } @@ -2060,7 +2054,7 @@ namespace MediaBrowser.Controller.Entities { var artist = FindParent<MusicArtist>(); - if (artist != null) + if (artist is not null) { return artist.GetImages(imageType).ElementAtOrDefault(imageIndex); } @@ -2147,7 +2141,7 @@ namespace MediaBrowser.Controller.Entities foreach (var newImage in images) { - if (newImage == null) + if (newImage is null) { throw new ArgumentException("null image found in list"); } @@ -2155,7 +2149,7 @@ namespace MediaBrowser.Controller.Entities var existing = existingImages .Find(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase)); - if (existing == null) + if (existing is null) { newImageList.Add(newImage); } @@ -2241,7 +2235,7 @@ namespace MediaBrowser.Controller.Entities var info1 = GetImageInfo(type, index1); var info2 = GetImageInfo(type, index2); - if (info1 == null || info2 == null) + if (info1 is null || info2 is null) { // Nothing to do return Task.CompletedTask; @@ -2274,14 +2268,14 @@ namespace MediaBrowser.Controller.Entities { var userdata = UserDataManager.GetUserData(user, this); - return userdata != null && userdata.Played; + return userdata is not null && userdata.Played; } public bool IsFavoriteOrLiked(User user) { var userdata = UserDataManager.GetUserData(user, this); - return userdata != null && (userdata.IsFavorite || (userdata.Likes ?? false)); + return userdata is not null && (userdata.IsFavorite || (userdata.Likes ?? false)); } public virtual bool IsUnplayed(User user) @@ -2290,7 +2284,7 @@ namespace MediaBrowser.Controller.Entities var userdata = UserDataManager.GetUserData(user, this); - return userdata == null || !userdata.Played; + return userdata is null || !userdata.Played; } ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo() @@ -2445,14 +2439,14 @@ namespace MediaBrowser.Controller.Entities // Try to retrieve it from the db. If we don't find it, use the resolved version var video = LibraryManager.GetItemById(id) as Video; - if (video == null) + if (video is null) { video = LibraryManager.ResolvePath(FileSystem.GetFileSystemInfo(path)) as Video; newOptions.ForceSave = true; } - if (video == null) + if (video is null) { return Task.FromResult(true); } @@ -2565,7 +2559,7 @@ namespace MediaBrowser.Controller.Entities { return ExtraIds .Select(LibraryManager.GetItemById) - .Where(i => i != null) + .Where(i => i is not null) .OrderBy(i => i.SortName); } @@ -2578,7 +2572,7 @@ namespace MediaBrowser.Controller.Entities { return ExtraIds .Select(LibraryManager.GetItemById) - .Where(i => i != null) + .Where(i => i is not null) .Where(i => i.ExtraType.HasValue && extraTypes.Contains(i.ExtraType.Value)) .OrderBy(i => i.SortName); } |
