aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2022-10-06 20:21:23 +0200
committerBond_009 <bond.009@outlook.com>2022-10-06 20:21:23 +0200
commita9a5fcde81060c9da2096235d61128006339a2ee (patch)
tree3c3f7da26dffcc1a6589bcfc1cec2a5634e92c0e /MediaBrowser.Common
parent927fe33d3a0ec7f9e0fb568cfd423c6e8b966c9d (diff)
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); ```
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Net/IPNetAddress.cs5
-rw-r--r--MediaBrowser.Common/Net/IPObject.cs25
-rw-r--r--MediaBrowser.Common/Net/NetworkExtensions.cs20
-rw-r--r--MediaBrowser.Common/Plugins/BasePluginOfT.cs5
4 files changed, 11 insertions, 44 deletions
diff --git a/MediaBrowser.Common/Net/IPNetAddress.cs b/MediaBrowser.Common/Net/IPNetAddress.cs
index f1428d4be..98d1c2d97 100644
--- a/MediaBrowser.Common/Net/IPNetAddress.cs
+++ b/MediaBrowser.Common/Net/IPNetAddress.cs
@@ -160,10 +160,7 @@ namespace MediaBrowser.Common.Net
/// <inheritdoc/>
public override bool Contains(IPAddress address)
{
- if (address == null)
- {
- throw new ArgumentNullException(nameof(address));
- }
+ ArgumentNullException.ThrowIfNull(address);
if (address.IsIPv4MappedToIPv6)
{
diff --git a/MediaBrowser.Common/Net/IPObject.cs b/MediaBrowser.Common/Net/IPObject.cs
index 3a5187bc3..37385972f 100644
--- a/MediaBrowser.Common/Net/IPObject.cs
+++ b/MediaBrowser.Common/Net/IPObject.cs
@@ -55,10 +55,7 @@ namespace MediaBrowser.Common.Net
/// <returns>IPAddress.</returns>
public static (IPAddress Address, byte PrefixLength) NetworkAddressOf(IPAddress address, byte prefixLength)
{
- if (address == null)
- {
- throw new ArgumentNullException(nameof(address));
- }
+ ArgumentNullException.ThrowIfNull(address);
if (address.IsIPv4MappedToIPv6)
{
@@ -109,10 +106,7 @@ namespace MediaBrowser.Common.Net
/// <returns>True if it is.</returns>
public static bool IsIP6(IPAddress address)
{
- if (address == null)
- {
- throw new ArgumentNullException(nameof(address));
- }
+ ArgumentNullException.ThrowIfNull(address);
if (address.IsIPv4MappedToIPv6)
{
@@ -129,10 +123,7 @@ namespace MediaBrowser.Common.Net
/// <returns>True if it contains a private address.</returns>
public static bool IsPrivateAddressRange(IPAddress address)
{
- if (address == null)
- {
- throw new ArgumentNullException(nameof(address));
- }
+ ArgumentNullException.ThrowIfNull(address);
if (!address.Equals(IPAddress.None))
{
@@ -179,10 +170,7 @@ namespace MediaBrowser.Common.Net
/// </remarks>
public static bool IsIPv6LinkLocal(IPAddress address)
{
- if (address == null)
- {
- throw new ArgumentNullException(nameof(address));
- }
+ ArgumentNullException.ThrowIfNull(address);
if (address.IsIPv4MappedToIPv6)
{
@@ -226,10 +214,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Byte CIDR representing the mask.</returns>
public static byte MaskToCidr(IPAddress mask)
{
- if (mask == null)
- {
- throw new ArgumentNullException(nameof(mask));
- }
+ ArgumentNullException.ThrowIfNull(mask);
byte cidrnet = 0;
if (!mask.Equals(IPAddress.Any))
diff --git a/MediaBrowser.Common/Net/NetworkExtensions.cs b/MediaBrowser.Common/Net/NetworkExtensions.cs
index 264bfacb4..7ad005854 100644
--- a/MediaBrowser.Common/Net/NetworkExtensions.cs
+++ b/MediaBrowser.Common/Net/NetworkExtensions.cs
@@ -61,10 +61,7 @@ namespace MediaBrowser.Common.Net
return false;
}
- if (item == null)
- {
- throw new ArgumentNullException(nameof(item));
- }
+ ArgumentNullException.ThrowIfNull(item);
if (item.IsIPv4MappedToIPv6)
{
@@ -96,10 +93,7 @@ namespace MediaBrowser.Common.Net
return false;
}
- if (item == null)
- {
- throw new ArgumentNullException(nameof(item));
- }
+ ArgumentNullException.ThrowIfNull(item);
foreach (var i in source)
{
@@ -153,10 +147,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Collection{IPObject} object containing the subnets.</returns>
public static Collection<IPObject> AsNetworks(this Collection<IPObject> source)
{
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
+ ArgumentNullException.ThrowIfNull(source);
Collection<IPObject> res = new Collection<IPObject>();
@@ -239,10 +230,7 @@ namespace MediaBrowser.Common.Net
return new Collection<IPObject>();
}
- if (target == null)
- {
- throw new ArgumentNullException(nameof(target));
- }
+ ArgumentNullException.ThrowIfNull(target);
Collection<IPObject> nc = new Collection<IPObject>();
diff --git a/MediaBrowser.Common/Plugins/BasePluginOfT.cs b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
index afda83a7c..0da5592d3 100644
--- a/MediaBrowser.Common/Plugins/BasePluginOfT.cs
+++ b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
@@ -164,10 +164,7 @@ namespace MediaBrowser.Common.Plugins
/// <inheritdoc />
public virtual void UpdateConfiguration(BasePluginConfiguration configuration)
{
- if (configuration == null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
Configuration = (TConfigurationType)configuration;