Use ArgumentException.ThrowIfNullOrEmpty

This commit is contained in:
Bond_009
2022-10-13 19:08:00 +02:00
parent 93fd462b58
commit b366dc2e6e
58 changed files with 130 additions and 549 deletions

View File

@@ -495,11 +495,7 @@ namespace Emby.Server.Implementations.Library
private Guid GetNewItemIdInternal(string key, Type type, bool forceCaseInsensitive)
{
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException(nameof(key));
}
ArgumentException.ThrowIfNullOrEmpty(key);
ArgumentNullException.ThrowIfNull(type);
string programDataPath = _configurationManager.ApplicationPaths.ProgramDataPath;
@@ -818,10 +814,7 @@ namespace Emby.Server.Implementations.Library
{
// If this returns multiple items it could be tricky figuring out which one is correct.
// In most cases, the newest one will be and the others obsolete but not yet cleaned up
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
ArgumentException.ThrowIfNullOrEmpty(path);
var query = new InternalItemsQuery
{
@@ -2340,10 +2333,7 @@ namespace Emby.Server.Implementations.Library
string sortName,
string uniqueId)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException(nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
var parentIdString = parentId.Equals(default)
? null
@@ -3125,10 +3115,7 @@ namespace Emby.Server.Implementations.Library
public void RemoveMediaPath(string virtualFolderName, string mediaPath)
{
if (string.IsNullOrEmpty(mediaPath))
{
throw new ArgumentNullException(nameof(mediaPath));
}
ArgumentException.ThrowIfNullOrEmpty(mediaPath);
var rootFolderPath = _configurationManager.ApplicationPaths.DefaultUserViewsPath;
var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);

View File

@@ -762,10 +762,7 @@ namespace Emby.Server.Implementations.Library
public Task<Tuple<MediaSourceInfo, IDirectStreamProvider>> GetLiveStreamWithDirectStreamProvider(string id, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}
ArgumentException.ThrowIfNullOrEmpty(id);
// TODO probably shouldn't throw here but it is kept for "backwards compatibility"
var info = GetLiveStreamInfo(id) ?? throw new ResourceNotFoundException();
@@ -774,10 +771,7 @@ namespace Emby.Server.Implementations.Library
public ILiveStream GetLiveStreamInfo(string id)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}
ArgumentException.ThrowIfNullOrEmpty(id);
if (_openStreams.TryGetValue(id, out ILiveStream info))
{
@@ -801,10 +795,7 @@ namespace Emby.Server.Implementations.Library
public async Task CloseLiveStream(string id)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}
ArgumentException.ThrowIfNullOrEmpty(id);
await _liveStreamSemaphore.WaitAsync().ConfigureAwait(false);
@@ -835,10 +826,7 @@ namespace Emby.Server.Implementations.Library
private (IMediaSourceProvider MediaSourceProvider, string KeyId) GetProvider(string key)
{
if (string.IsNullOrEmpty(key))
{
throw new ArgumentException("Key can't be empty.", nameof(key));
}
ArgumentException.ThrowIfNullOrEmpty(key);
var keys = key.Split(LiveStreamIdDelimeter, 2);

View File

@@ -25,10 +25,7 @@ namespace Emby.Server.Implementations.Library
public static bool SetInitialItemValues(BaseItem item, Folder? parent, ILibraryManager libraryManager, IDirectoryService directoryService)
{
// This version of the below method has no ItemResolveArgs, so we have to require the path already being set
if (string.IsNullOrEmpty(item.Path))
{
throw new ArgumentException("Item must have a Path");
}
ArgumentException.ThrowIfNullOrEmpty(item.Path);
// If the resolver didn't specify this
if (parent is not null)

View File

@@ -73,10 +73,7 @@ namespace Emby.Server.Implementations.Library
{
var searchTerm = query.SearchTerm;
if (string.IsNullOrEmpty(searchTerm))
{
throw new ArgumentException("SearchTerm can't be empty.", nameof(query));
}
ArgumentException.ThrowIfNullOrEmpty(searchTerm);
searchTerm = searchTerm.Trim().RemoveDiacritics();