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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 60 additions and 200 deletions

View File

@ -335,10 +335,7 @@ namespace Emby.Server.Implementations
{ {
get get
{ {
if (_deviceId == null) _deviceId ??= new DeviceId(ApplicationPaths, LoggerFactory);
{
_deviceId = new DeviceId(ApplicationPaths, LoggerFactory);
}
return _deviceId.Value; return _deviceId.Value;
} }
@ -370,10 +367,7 @@ namespace Emby.Server.Implementations
/// <returns>System.Object.</returns> /// <returns>System.Object.</returns>
protected object CreateInstanceSafe(Type type) protected object CreateInstanceSafe(Type type)
{ {
if (_creatingInstances == null) _creatingInstances ??= new List<Type>();
{
_creatingInstances = new List<Type>();
}
if (_creatingInstances.IndexOf(type) != -1) if (_creatingInstances.IndexOf(type) != -1)
{ {

View File

@ -665,10 +665,7 @@ namespace Emby.Server.Implementations.Dto
var tag = GetImageCacheTag(item, image); var tag = GetImageCacheTag(item, image);
if (!string.IsNullOrEmpty(image.BlurHash)) if (!string.IsNullOrEmpty(image.BlurHash))
{ {
if (dto.ImageBlurHashes == null) dto.ImageBlurHashes ??= new Dictionary<ImageType, Dictionary<string, string>>();
{
dto.ImageBlurHashes = new Dictionary<ImageType, Dictionary<string, string>>();
}
if (!dto.ImageBlurHashes.ContainsKey(image.Type)) if (!dto.ImageBlurHashes.ContainsKey(image.Type))
{ {
@ -702,10 +699,7 @@ namespace Emby.Server.Implementations.Dto
if (hashes.Count > 0) if (hashes.Count > 0)
{ {
if (dto.ImageBlurHashes == null) dto.ImageBlurHashes ??= new Dictionary<ImageType, Dictionary<string, string>>();
{
dto.ImageBlurHashes = new Dictionary<ImageType, Dictionary<string, string>>();
}
dto.ImageBlurHashes[imageType] = hashes; dto.ImageBlurHashes[imageType] = hashes;
} }
@ -898,10 +892,7 @@ namespace Emby.Server.Implementations.Dto
dto.Taglines = new string[] { item.Tagline }; dto.Taglines = new string[] { item.Tagline };
} }
if (dto.Taglines == null) dto.Taglines ??= Array.Empty<string>();
{
dto.Taglines = Array.Empty<string>();
}
} }
dto.Type = item.GetBaseItemKind(); dto.Type = item.GetBaseItemKind();

View File

@ -176,10 +176,7 @@ namespace Emby.Server.Implementations.Library
{ {
lock (_rootFolderSyncLock) lock (_rootFolderSyncLock)
{ {
if (_rootFolder == null) _rootFolder ??= CreateRootFolder();
{
_rootFolder = CreateRootFolder();
}
} }
} }

View File

@ -35,14 +35,10 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
return null; return null;
} }
var season = parent as Season;
// Just in case the user decided to nest episodes. // Just in case the user decided to nest episodes.
// Not officially supported but in some cases we can handle it. // Not officially supported but in some cases we can handle it.
if (season == null)
{ var season = parent as Season ?? parent.GetParents().OfType<Season>().FirstOrDefault();
season = parent.GetParents().OfType<Season>().FirstOrDefault();
}
// If the parent is a Season or Series and the parent is not an extras folder, then this is an Episode if the VideoResolver returns something // If the parent is a Season or Series and the parent is not an extras folder, then this is an Episode if the VideoResolver returns something
// Also handle flat tv folders // Also handle flat tv folders
@ -55,11 +51,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
if (episode != null) if (episode != null)
{ {
var series = parent as Series; var series = parent as Series ?? parent.GetParents().OfType<Series>().FirstOrDefault();
if (series == null)
{
series = parent.GetParents().OfType<Series>().FirstOrDefault();
}
if (series != null) if (series != null)
{ {

View File

@ -2237,14 +2237,10 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var enabledTimersForSeries = new List<TimerInfo>(); var enabledTimersForSeries = new List<TimerInfo>();
foreach (var timer in allTimers) foreach (var timer in allTimers)
{ {
var existingTimer = _timerProvider.GetTimer(timer.Id); var existingTimer = _timerProvider.GetTimer(timer.Id)
?? (string.IsNullOrWhiteSpace(timer.ProgramId)
if (existingTimer == null)
{
existingTimer = string.IsNullOrWhiteSpace(timer.ProgramId)
? null ? null
: _timerProvider.GetTimerByProgramId(timer.ProgramId); : _timerProvider.GetTimerByProgramId(timer.ProgramId));
}
if (existingTimer == null) if (existingTimer == null)
{ {

View File

@ -787,14 +787,11 @@ namespace Emby.Server.Implementations.LiveTv.Listings
{ {
var channelNumber = GetChannelNumber(channel); var channelNumber = GetChannelNumber(channel);
var station = allStations.Find(item => string.Equals(item.stationID, channel.stationID, StringComparison.OrdinalIgnoreCase)); var station = allStations.Find(item => string.Equals(item.stationID, channel.stationID, StringComparison.OrdinalIgnoreCase))
if (station == null) ?? new ScheduleDirect.Station
{
station = new ScheduleDirect.Station
{ {
stationID = channel.stationID stationID = channel.stationID
}; };
}
var channelInfo = new ChannelInfo var channelInfo = new ChannelInfo
{ {

View File

@ -987,10 +987,7 @@ namespace Emby.Server.Implementations.LiveTv
var externalProgramId = programTuple.Item2; var externalProgramId = programTuple.Item2;
string externalSeriesId = programTuple.Item3; string externalSeriesId = programTuple.Item3;
if (timerList == null) timerList ??= (await GetTimersInternal(new TimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
{
timerList = (await GetTimersInternal(new TimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
}
var timer = timerList.FirstOrDefault(i => string.Equals(i.ProgramId, externalProgramId, StringComparison.OrdinalIgnoreCase)); var timer = timerList.FirstOrDefault(i => string.Equals(i.ProgramId, externalProgramId, StringComparison.OrdinalIgnoreCase));
var foundSeriesTimer = false; var foundSeriesTimer = false;
@ -1018,10 +1015,7 @@ namespace Emby.Server.Implementations.LiveTv
continue; continue;
} }
if (seriesTimerList == null) seriesTimerList ??= (await GetSeriesTimersInternal(new SeriesTimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
{
seriesTimerList = (await GetSeriesTimersInternal(new SeriesTimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
}
var seriesTimer = seriesTimerList.FirstOrDefault(i => string.Equals(i.SeriesId, externalSeriesId, StringComparison.OrdinalIgnoreCase)); var seriesTimer = seriesTimerList.FirstOrDefault(i => string.Equals(i.SeriesId, externalSeriesId, StringComparison.OrdinalIgnoreCase));
@ -1974,10 +1968,7 @@ namespace Emby.Server.Implementations.LiveTv
}; };
} }
if (service == null) service ??= _services[0];
{
service = _services[0];
}
var info = await service.GetNewTimerDefaultsAsync(cancellationToken, programInfo).ConfigureAwait(false); var info = await service.GetNewTimerDefaultsAsync(cancellationToken, programInfo).ConfigureAwait(false);

View File

@ -421,10 +421,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
string audioCodec = channelInfo.AudioCodec; string audioCodec = channelInfo.AudioCodec;
if (!videoBitrate.HasValue) videoBitrate ??= isHd ? 15000000 : 2000000;
{
videoBitrate = isHd ? 15000000 : 2000000;
}
int? audioBitrate = isHd ? 448000 : 192000; int? audioBitrate = isHd ? 448000 : 192000;

View File

@ -44,12 +44,7 @@ namespace Emby.Server.Implementations.Plugins
{ {
get get
{ {
if (_httpClientFactory == null) return _httpClientFactory ?? (_httpClientFactory = _appHost.Resolve<IHttpClientFactory>());
{
_httpClientFactory = _appHost.Resolve<IHttpClientFactory>();
}
return _httpClientFactory;
} }
} }
@ -276,11 +271,7 @@ namespace Emby.Server.Implementations.Plugins
// If no version is given, return the current instance. // If no version is given, return the current instance.
var plugins = _plugins.Where(p => p.Id.Equals(id)).ToList(); var plugins = _plugins.Where(p => p.Id.Equals(id)).ToList();
plugin = plugins.FirstOrDefault(p => p.Instance != null); plugin = plugins.FirstOrDefault(p => p.Instance != null) ?? plugins.OrderByDescending(p => p.Version).FirstOrDefault();
if (plugin == null)
{
plugin = plugins.OrderByDescending(p => p.Version).FirstOrDefault();
}
} }
else else
{ {

View File

@ -301,12 +301,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
{ {
get get
{ {
if (_id == null) return _id ??= ScheduledTask.GetType().FullName.GetMD5().ToString("N", CultureInfo.InvariantCulture);
{
_id = ScheduledTask.GetType().FullName.GetMD5().ToString("N", CultureInfo.InvariantCulture);
}
return _id;
} }
} }

View File

@ -1475,10 +1475,7 @@ namespace Emby.Server.Implementations.Session
user = _userManager.GetUserById(request.UserId); user = _userManager.GetUserById(request.UserId);
} }
if (user == null) user ??= _userManager.GetUserByName(request.Username);
{
user = _userManager.GetUserByName(request.Username);
}
if (enforcePassword) if (enforcePassword)
{ {

View File

@ -207,12 +207,7 @@ namespace Jellyfin.Api.Controllers
var plugins = _pluginManager.Plugins.Where(p => p.Id.Equals(pluginId)); var plugins = _pluginManager.Plugins.Where(p => p.Id.Equals(pluginId));
// Select the un-instanced one first. // Select the un-instanced one first.
var plugin = plugins.FirstOrDefault(p => p.Instance == null); var plugin = plugins.FirstOrDefault(p => p.Instance == null) ?? plugins.OrderBy(p => p.Manifest.Status).FirstOrDefault();
if (plugin == null)
{
// Then by the status.
plugin = plugins.OrderBy(p => p.Manifest.Status).FirstOrDefault();
}
if (plugin != null) if (plugin != null)
{ {

View File

@ -228,10 +228,7 @@ namespace Jellyfin.Api.Controllers
itemWithImage = GetParentWithImage<Series>(item, ImageType.Thumb); itemWithImage = GetParentWithImage<Series>(item, ImageType.Thumb);
} }
if (itemWithImage == null) itemWithImage ??= GetParentWithImage<BaseItem>(item, ImageType.Thumb);
{
itemWithImage = GetParentWithImage<BaseItem>(item, ImageType.Thumb);
}
if (itemWithImage != null) if (itemWithImage != null)
{ {

View File

@ -292,10 +292,7 @@ namespace Jellyfin.Api.Helpers
} }
} }
if (profile == null) profile ??= dlnaManager.GetDefaultProfile();
{
profile = dlnaManager.GetDefaultProfile();
}
var audioCodec = state.ActualOutputAudioCodec; var audioCodec = state.ActualOutputAudioCodec;

View File

@ -400,10 +400,7 @@ namespace MediaBrowser.Common.Net
private bool ResolveHost() private bool ResolveHost()
{ {
// When was the last time we resolved? // When was the last time we resolved?
if (_lastResolved == null) _lastResolved ??= DateTime.UtcNow;
{
_lastResolved = DateTime.UtcNow;
}
// If we haven't resolved before, or our timer has run out... // If we haven't resolved before, or our timer has run out...
if ((_addresses.Length == 0 && !Resolved) || (DateTime.UtcNow > _lastResolved.Value.AddMinutes(Timeout))) if ((_addresses.Length == 0 && !Resolved) || (DateTime.UtcNow > _lastResolved.Value.AddMinutes(Timeout)))

View File

@ -105,10 +105,7 @@ namespace MediaBrowser.Common.Plugins
{ {
lock (_configurationSyncLock) lock (_configurationSyncLock)
{ {
if (_configuration == null) _configuration ??= LoadConfiguration();
{
_configuration = LoadConfiguration();
}
} }
} }

View File

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

View File

@ -75,10 +75,7 @@ namespace MediaBrowser.Controller.Entities
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query) 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; query.EnableTotalRecordCount = false;
var result = GetItemList(query); 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)); 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); AdditionalLocations.Add(path);
} }

View File

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

View File

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

View File

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

View File

@ -1187,43 +1187,28 @@ namespace MediaBrowser.MediaEncoding.Probing
FetchStudios(audio, tags, "label"); FetchStudios(audio, tags, "label");
// These support mulitple values, but for now we only store the first. // These support mulitple values, but for now we only store the first.
var mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Album Artist Id")); var mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Album Artist Id"))
if (mb == null) ?? GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_ALBUMARTISTID"));
{
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_ALBUMARTISTID"));
}
audio.SetProviderId(MetadataProvider.MusicBrainzAlbumArtist, mb); audio.SetProviderId(MetadataProvider.MusicBrainzAlbumArtist, mb);
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Artist Id")); mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Artist Id"))
if (mb == null) ?? GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_ARTISTID"));
{
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_ARTISTID"));
}
audio.SetProviderId(MetadataProvider.MusicBrainzArtist, mb); audio.SetProviderId(MetadataProvider.MusicBrainzArtist, mb);
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Album Id")); mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Album Id"))
if (mb == null) ?? GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_ALBUMID"));
{
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_ALBUMID"));
}
audio.SetProviderId(MetadataProvider.MusicBrainzAlbum, mb); audio.SetProviderId(MetadataProvider.MusicBrainzAlbum, mb);
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Release Group Id")); mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Release Group Id"))
if (mb == null) ?? GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_RELEASEGROUPID"));
{
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_RELEASEGROUPID"));
}
audio.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, mb); audio.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, mb);
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Release Track Id")); mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Release Track Id"))
if (mb == null) ?? GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_RELEASETRACKID"));
{
mb = GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MUSICBRAINZ_RELEASETRACKID"));
}
audio.SetProviderId(MetadataProvider.MusicBrainzTrack, mb); audio.SetProviderId(MetadataProvider.MusicBrainzTrack, mb);
} }
@ -1290,15 +1275,7 @@ namespace MediaBrowser.MediaEncoding.Probing
private IEnumerable<string> GetSplitWhitelist() private IEnumerable<string> GetSplitWhitelist()
{ {
if (_splitWhiteList == null) return _splitWhiteList ??= new List<string> { "AC/DC" };
{
_splitWhiteList = new List<string>
{
"AC/DC"
};
}
return _splitWhiteList;
} }
/// <summary> /// <summary>

View File

@ -123,10 +123,7 @@ namespace MediaBrowser.Model.Entities
else else
{ {
// Ensure it exists // Ensure it exists
if (instance.ProviderIds == null) instance.ProviderIds ??= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
{
instance.ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
instance.ProviderIds[name] = value; instance.ProviderIds[name] = value;
} }

View File

@ -111,10 +111,7 @@ namespace MediaBrowser.Providers.MediaInfo
} }
} }
if (streamFileNames == null) streamFileNames ??= Array.Empty<string>();
{
streamFileNames = Array.Empty<string>();
}
mediaInfoResult = await GetMediaInfo(item, cancellationToken).ConfigureAwait(false); mediaInfoResult = await GetMediaInfo(item, cancellationToken).ConfigureAwait(false);

View File

@ -256,10 +256,7 @@ namespace MediaBrowser.Providers.Subtitles
} }
catch (Exception ex) catch (Exception ex)
{ {
if (exceptionToThrow == null) exceptionToThrow ??= ex;
{
exceptionToThrow = ex;
}
} }
finally finally
{ {

View File

@ -415,10 +415,7 @@ namespace Rssdp.Infrastructure
{ {
lock (_SendSocketSynchroniser) lock (_SendSocketSynchroniser)
{ {
if (_sendSockets == null) _sendSockets ??= CreateSocketAndListenForResponsesAsync();
{
_sendSockets = CreateSocketAndListenForResponsesAsync();
}
} }
} }
} }