Code Clean up: Convert to null-coalescing operator ?? (#5845)

Co-authored-by: Cody Robibero <cody@robibe.ro>
Co-authored-by: Patrick Barron <18354464+barronpm@users.noreply.github.com>
This commit is contained in:
BaronGreenback
2021-05-05 12:51:14 +01:00
committed by GitHub
parent 04447ed014
commit 2e98de9062
27 changed files with 60 additions and 200 deletions

View File

@@ -106,15 +106,10 @@ namespace MediaBrowser.Controller.Entities
{
get
{
if (_themeSongIds == null)
{
_themeSongIds = GetExtras()
.Where(extra => extra.ExtraType == Model.Entities.ExtraType.ThemeSong)
.Select(song => song.Id)
.ToArray();
}
return _themeSongIds;
return _themeSongIds ??= GetExtras()
.Where(extra => extra.ExtraType == Model.Entities.ExtraType.ThemeSong)
.Select(song => song.Id)
.ToArray();
}
private set
@@ -128,15 +123,10 @@ namespace MediaBrowser.Controller.Entities
{
get
{
if (_themeVideoIds == null)
{
_themeVideoIds = GetExtras()
.Where(extra => extra.ExtraType == Model.Entities.ExtraType.ThemeVideo)
.Select(song => song.Id)
.ToArray();
}
return _themeVideoIds;
return _themeVideoIds ??= GetExtras()
.Where(extra => extra.ExtraType == Model.Entities.ExtraType.ThemeVideo)
.Select(song => song.Id)
.ToArray();
}
private set

View File

@@ -75,10 +75,7 @@ namespace MediaBrowser.Controller.Entities
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
{
if (query == null)
{
query = new InternalItemsQuery(user);
}
query ??= new InternalItemsQuery(user);
query.EnableTotalRecordCount = false;
var result = GetItemList(query);

View File

@@ -147,10 +147,7 @@ namespace MediaBrowser.Controller.Library
throw new ArgumentException("The path was empty or null.", nameof(path));
}
if (AdditionalLocations == null)
{
AdditionalLocations = new List<string>();
}
AdditionalLocations ??= new List<string>();
AdditionalLocations.Add(path);
}

View File

@@ -126,10 +126,7 @@ namespace MediaBrowser.Controller.Playlists
private List<BaseItem> GetPlayableItems(User user, InternalItemsQuery query)
{
if (query == null)
{
query = new InternalItemsQuery(user);
}
query ??= new InternalItemsQuery(user);
query.IsFolder = false;

View File

@@ -45,10 +45,7 @@ namespace MediaBrowser.Controller.Providers
if (copy.RefreshPaths != null && copy.RefreshPaths.Length > 0)
{
if (RefreshPaths == null)
{
RefreshPaths = Array.Empty<string>();
}
RefreshPaths ??= Array.Empty<string>();
RefreshPaths = copy.RefreshPaths.ToArray();
}

View File

@@ -37,10 +37,7 @@ namespace MediaBrowser.Controller.Providers
public void AddPerson(PersonInfo p)
{
if (People == null)
{
People = new List<PersonInfo>();
}
People ??= new List<PersonInfo>();
PeopleHelper.AddPerson(People, p);
}
@@ -54,16 +51,15 @@ namespace MediaBrowser.Controller.Providers
{
People = new List<PersonInfo>();
}
People.Clear();
else
{
People.Clear();
}
}
public UserItemData GetOrAddUserData(string userId)
{
if (UserDataList == null)
{
UserDataList = new List<UserItemData>();
}
UserDataList ??= new List<UserItemData>();
UserItemData userData = null;