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

@@ -24,15 +24,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
var episode1 = x as Episode;
var episode2 = y as Episode;

View File

@@ -23,15 +23,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
return (x.CommunityRating ?? 0).CompareTo(y.CommunityRating ?? 0);
}

View File

@@ -24,15 +24,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
return DateTime.Compare(x.DateCreated, y.DateCreated);
}

View File

@@ -24,15 +24,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
if (!x.IndexNumber.HasValue && !y.IndexNumber.HasValue)
{

View File

@@ -24,15 +24,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
return string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase);
}

View File

@@ -31,15 +31,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
var levelX = string.IsNullOrEmpty(x.OfficialRating) ? 0 : _localization.GetRatingLevel(x.OfficialRating) ?? 0;
var levelY = string.IsNullOrEmpty(y.OfficialRating) ? 0 : _localization.GetRatingLevel(y.OfficialRating) ?? 0;

View File

@@ -24,15 +24,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
if (!x.ParentIndexNumber.HasValue && !y.ParentIndexNumber.HasValue)
{

View File

@@ -26,15 +26,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
return (x.RunTimeTicks ?? 0).CompareTo(y.RunTimeTicks ?? 0);
}

View File

@@ -26,15 +26,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
return string.Compare(x.SortName, y.SortName, StringComparison.OrdinalIgnoreCase);
}

View File

@@ -26,15 +26,9 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
ArgumentNullException.ThrowIfNull(x);
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
ArgumentNullException.ThrowIfNull(y);
return AlphanumericComparator.CompareValues(x.Studios.FirstOrDefault(), y.Studios.FirstOrDefault());
}