diff options
| author | Claus Vium <cvium@users.noreply.github.com> | 2022-10-07 09:57:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 09:57:16 +0200 |
| commit | 81b04ddbb54201d2e07310e3c700cca8a94d8955 (patch) | |
| tree | a4e9aeb70e35b3e47a7d8af17b328e88a1c77ed0 /MediaBrowser.Common/Net | |
| parent | 6bf71c0fd355e9c95a1e142019d9bc5cce34200d (diff) | |
| parent | 14027f962ce074623fd89967ca9565bbeb785066 (diff) | |
Merge branch 'master' into providermanager-cleanup
Diffstat (limited to 'MediaBrowser.Common/Net')
| -rw-r--r-- | MediaBrowser.Common/Net/IPNetAddress.cs | 5 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/IPObject.cs | 54 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/NamedClient.cs | 5 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/NetworkExtensions.cs | 20 |
4 files changed, 17 insertions, 67 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 bd5368882..37385972f 100644 --- a/MediaBrowser.Common/Net/IPObject.cs +++ b/MediaBrowser.Common/Net/IPObject.cs @@ -55,17 +55,14 @@ 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) { address = address.MapToIPv4(); } - if (IsLoopback(address)) + if (IPAddress.IsLoopback(address)) { return (address, prefixLength); } @@ -103,41 +100,13 @@ namespace MediaBrowser.Common.Net } /// <summary> - /// Tests to see if the ip address is a Loopback address. - /// </summary> - /// <param name="address">Value to test.</param> - /// <returns>True if it is.</returns> - public static bool IsLoopback(IPAddress address) - { - if (address == null) - { - throw new ArgumentNullException(nameof(address)); - } - - if (!address.Equals(IPAddress.None)) - { - if (address.IsIPv4MappedToIPv6) - { - address = address.MapToIPv4(); - } - - return address.Equals(IPAddress.Loopback) || address.Equals(IPAddress.IPv6Loopback); - } - - return false; - } - - /// <summary> /// Tests to see if the ip address is an IP6 address. /// </summary> /// <param name="address">Value to test.</param> /// <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) { @@ -154,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)) { @@ -204,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) { @@ -251,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)) @@ -295,7 +255,7 @@ namespace MediaBrowser.Common.Net /// <returns>True if it is.</returns> public virtual bool IsLoopback() { - return IsLoopback(Address); + return IPAddress.IsLoopback(Address); } /// <summary> diff --git a/MediaBrowser.Common/Net/NamedClient.cs b/MediaBrowser.Common/Net/NamedClient.cs index 0f6161c32..a6cacd4f1 100644 --- a/MediaBrowser.Common/Net/NamedClient.cs +++ b/MediaBrowser.Common/Net/NamedClient.cs @@ -14,5 +14,10 @@ /// Gets the value for the MusicBrainz named http client. /// </summary> public const string MusicBrainz = nameof(MusicBrainz); + + /// <summary> + /// Gets the value for the DLNA named http client. + /// </summary> + public const string Dlna = nameof(Dlna); } } 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>(); |
