Use ArgumentNullException.ThrowIfNull helper method

Did a simple search/replace on the whole repo (except the RSSDP project)
This reduces LOC and should improve performance (methods containing a throw statement don't get inlined)

```
if \((\w+) == null\)
\s+\{
\s+throw new ArgumentNullException\((.*)\);
\s+\}
```

```
ArgumentNullException.ThrowIfNull($1);
```
This commit is contained in:
Bond_009
2022-10-06 20:21:23 +02:00
parent 927fe33d3a
commit a9a5fcde81
60 changed files with 155 additions and 617 deletions

View File

@@ -92,25 +92,13 @@ namespace Emby.Server.Implementations.ScheduledTasks
/// </exception>
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, ILogger logger)
{
if (scheduledTask == null)
{
throw new ArgumentNullException(nameof(scheduledTask));
}
ArgumentNullException.ThrowIfNull(scheduledTask);
if (applicationPaths == null)
{
throw new ArgumentNullException(nameof(applicationPaths));
}
ArgumentNullException.ThrowIfNull(applicationPaths);
if (taskManager == null)
{
throw new ArgumentNullException(nameof(taskManager));
}
ArgumentNullException.ThrowIfNull(taskManager);
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
ArgumentNullException.ThrowIfNull(logger);
ScheduledTask = scheduledTask;
_applicationPaths = applicationPaths;
@@ -249,10 +237,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
get => _triggers;
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
ArgumentNullException.ThrowIfNull(value);
// Cleanup current triggers
if (_triggers != null)
@@ -281,10 +266,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
ArgumentNullException.ThrowIfNull(value);
// This null check is not great, but is needed to handle bad user input, or user mucking with the config file incorrectly
var triggerList = value.Where(i => i != null).ToArray();