Skip to content

Commit 63025f9

Browse files
authored
Merge pull request #383 from lduchosal/feat/v4-nullable
feat/v4-nullable
2 parents 4178c96 + 97da019 commit 63025f9

File tree

70 files changed

+566
-603
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+566
-603
lines changed

src/ConsoleApplication/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static class Program
4545
}
4646

4747
ac.CidrParse = CidrParse.Value;
48-
ac.CidrParsed = (byte)cidr!;
48+
ac.CidrParsed = (byte)cidr;
4949
}),
5050
new ArgParsed('s', (ac, arg) =>
5151
{
@@ -57,7 +57,7 @@ public static class Program
5757
}
5858

5959
ac.Action = Action.Subnet;
60-
ac.SubnetCidr = (byte)cidr!;
60+
ac.SubnetCidr = (byte)cidr;
6161
}),
6262
new ArgParsed('C', (ac, arg) =>
6363
{

src/System.Net.IPNetwork/CidrClassFull.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public sealed class CidrClassFull : ICidrGuess
2727
/// <param name="ip">A string representing the CIDR to convert.</param>
2828
/// <param name="cidr">A byte representing the netmask in cidr format (/24).</param>
2929
/// <returns>true if ip was converted successfully; otherwise, false.</returns>
30-
public bool TryGuessCidr(string ip, out byte cidr)
30+
public bool TryGuessCidr(string? ip, out byte cidr)
3131
{
32-
bool parsed = IPAddress.TryParse($"{ip}", out var ipaddress);
33-
if (!parsed)
32+
if (!IPAddress.TryParse($"{ip}", out var ipaddress))
3433
{
3534
cidr = 0;
3635
return false;

src/System.Net.IPNetwork/CidrClassLess.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ public sealed class CidrClassLess : ICidrGuess
2020
/// <param name="ip">A string representing an IPAddress that will be used to guess CIDR.</param>
2121
/// <param name="cidr">A byte representing the netmask in cidr format (/24).</param>
2222
/// <returns>true if ip was converted successfully; otherwise, false.</returns>
23-
public bool TryGuessCidr(string ip, out byte cidr)
23+
public bool TryGuessCidr(string? ip, out byte cidr)
2424
{
25-
bool parsed = IPAddress.TryParse($"{ip}", out IPAddress ipaddress);
26-
if (!parsed)
25+
if (!IPAddress.TryParse($"{ip}", out IPAddress? ipaddress))
2726
{
2827
cidr = 0;
2928
return false;

src/System.Net.IPNetwork/CidrNetworkAware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public sealed class CidrNetworkAware : ICidrGuess
6161
/// <param name="ip">IP address as string (no slash). Example: "192.0.43.0" or "2001:db8::".</param>
6262
/// <param name="cidr">Guessed CIDR (0..32 for IPv4, 0..128 for IPv6).</param>
6363
/// <returns>true if parsed and guessed; false if input is not a valid IP address.</returns>
64-
public bool TryGuessCidr(string ip, out byte cidr)
64+
public bool TryGuessCidr(string? ip, out byte cidr)
6565
{
6666
cidr = 0;
6767
if (string.IsNullOrWhiteSpace(ip))
6868
return false;
6969

7070
// Reject if user passed a slash - this API expects a plain address.
7171
// (You can relax this if you want to honor an explicitly supplied prefix.)
72-
if (ip.Contains("/"))
72+
if (ip.Contains('/'))
7373
return false;
7474

7575
if (!IPAddress.TryParse(ip.Trim(), out var ipAddress))

src/System.Net.IPNetwork/Filter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public enum Filter
1919
/// <summary>
2020
/// Represents different filters for a collection of items.
2121
/// </summary>
22-
[Obsolete("Use Filter instead")]
2322
public enum FilterEnum
2423
{
2524
/// <summary>

src/System.Net.IPNetwork/ICidrGuess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public interface ICidrGuess
1515
/// <param name="ip">An IPAddress to guess the ip network CIDR.</param>
1616
/// <param name="cidr">A byte representing the netmask in cidr format (/24).</param>
1717
/// <returns>true if ip was converted successfully; otherwise, false.</returns>
18-
bool TryGuessCidr(string ip, out byte cidr);
18+
bool TryGuessCidr(string? ip, out byte cidr);
1919
}

src/System.Net.IPNetwork/IPNetwork2Contains.cs

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,6 @@ namespace System.Net;
1212
/// </summary>
1313
public sealed partial class IPNetwork2
1414
{
15-
/// <summary>
16-
/// Determines whether the given IP address is part of the given IP network.
17-
/// </summary>
18-
/// <param name="network">The IP network.</param>
19-
/// <param name="ipaddress">The IP address.</param>
20-
/// <returns>
21-
/// <c>true</c> if the IP address is part of the IP network; otherwise, <c>false</c>.
22-
/// </returns>
23-
[Obsolete("static Contains is deprecated, please use instance Contains.")]
24-
public static bool Contains(IPNetwork2 network, IPAddress ipaddress)
25-
{
26-
if (network == null)
27-
{
28-
throw new ArgumentNullException(nameof(network));
29-
}
30-
31-
return network.Contains(ipaddress);
32-
}
33-
34-
/// <summary>
35-
/// Determines if the given <paramref name="network"/> contains the specified <paramref name="network2"/>.
36-
/// </summary>
37-
/// <param name="network">The network to check for containment.</param>
38-
/// <param name="network2">The network to check if it is contained.</param>
39-
/// <returns>
40-
/// <c>true</c> if the <paramref name="network"/> contains the <paramref name="network2"/>; otherwise, <c>false</c>.
41-
/// </returns>
42-
[Obsolete("static Contains is deprecated, please use instance Contains.")]
43-
public static bool Contains(IPNetwork2 network, IPNetwork2 network2)
44-
{
45-
if (network == null)
46-
{
47-
throw new ArgumentNullException(nameof(network));
48-
}
49-
50-
return network.Contains(network2);
51-
}
52-
5315
/// <summary>
5416
/// return true if ipaddress is contained in network.
5517
/// </summary>
@@ -106,6 +68,38 @@ public bool Contains(IPNetwork2 contains)
10668
return result;
10769
}
10870

71+
/// <summary>
72+
/// return true if ipaddress is contained in network.
73+
/// </summary>
74+
/// <param name="network">The network.</param>
75+
/// <param name="ipaddress">The ip address to test.</param>
76+
/// <returns>true if ipaddress is contained into the IP Network; otherwise, false.</returns>
77+
public static bool Contains(IPNetwork2 network, IPAddress ipaddress)
78+
{
79+
if (network == null)
80+
{
81+
throw new ArgumentNullException(nameof(network));
82+
}
83+
84+
return network.Contains(ipaddress);
85+
}
86+
87+
/// <summary>
88+
/// return true is network2 is fully contained in network.
89+
/// </summary>
90+
/// <param name="network">The network.</param>
91+
/// <param name="network2">The network to test.</param>
92+
/// <returns>true if network2 is contained into the IP Network; otherwise, false.</returns>
93+
public static bool Contains(IPNetwork2 network, IPNetwork2 network2)
94+
{
95+
if (network == null)
96+
{
97+
throw new ArgumentNullException(nameof(network));
98+
}
99+
100+
return network.Contains(network2);
101+
}
102+
109103
private static BigInteger CreateBroadcast(ref BigInteger network, BigInteger netmask, AddressFamily family)
110104
{
111105
int width = family == AddressFamily.InterNetwork ? 4 : 16;

src/System.Net.IPNetwork/IPNetwork2IANAblock.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,11 @@ public static bool IsIANAReserved(IPAddress ipaddress)
6868
}
6969

7070
/// <summary>
71-
/// Determines whether the specified IP network is reserved according to the IANA Reserved ranges.
71+
/// return true if ipnetwork is contained in
72+
/// IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1.
7273
/// </summary>
73-
/// <param name="ipnetwork">The IP network to check.</param>
74-
/// <returns>
75-
/// <c>true</c> if the specified IP network is reserved according to the IANA Reserved ranges; otherwise, <c>false</c>.
76-
/// </returns>
77-
/// <remarks>
78-
/// <para>
79-
/// This method is obsolete and should not be used. Please use the instance method, see IsIANAReserved" instead.
80-
/// </para>
81-
/// <para>
82-
/// Throws an <see cref="ArgumentNullException"/> if <paramref name="ipnetwork"/> is <c>null</c>.
83-
/// </para>
84-
/// </remarks>
85-
[Obsolete("static IsIANAReserved is deprecated, please use instance IsIANAReserved.")]
74+
/// <param name="ipnetwork">The IPNetwork to test.</param>
75+
/// <returns>true if the ipnetwork is a IANA reserverd IP Netowkr ; otherwise, false.</returns>
8676
public static bool IsIANAReserved(IPNetwork2 ipnetwork)
8777
{
8878
if (ipnetwork == null)

src/System.Net.IPNetwork/IPNetwork2IComparableIPNetworkMembers.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public sealed partial class IPNetwork2
2020
/// A negative value if <paramref name="left"/> is less than <paramref name="right"/>.
2121
/// A positive value if <paramref name="left"/> is greater than <paramref name="right"/>.
2222
/// </returns>
23-
public static int Compare(IPNetwork2 left, IPNetwork2 right)
23+
public static int Compare(IPNetwork2? left, IPNetwork2? right)
2424
{
2525
// two null IPNetworks are equal
26-
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
26+
if (left is null && right is null)
2727
{
2828
return 0;
2929
}
@@ -35,12 +35,12 @@ public static int Compare(IPNetwork2 left, IPNetwork2 right)
3535
}
3636

3737
// null is always sorted first
38-
if (ReferenceEquals(left, null))
38+
if (left is null)
3939
{
4040
return -1;
4141
}
4242

43-
if (ReferenceEquals(right, null))
43+
if (right is null)
4444
{
4545
return 1;
4646
}
@@ -69,7 +69,7 @@ public static int Compare(IPNetwork2 left, IPNetwork2 right)
6969
/// </summary>
7070
/// <param name="other">The other network to compare to.</param>
7171
/// <returns>A signed number indicating the relative values of this instance and value.</returns>
72-
public int CompareTo(IPNetwork2 other)
72+
public int CompareTo(IPNetwork2? other)
7373
{
7474
return Compare(this, other);
7575
}
@@ -79,7 +79,7 @@ public int CompareTo(IPNetwork2 other)
7979
/// </summary>
8080
/// <param name="obj">The other object to compare to.</param>
8181
/// <returns>A signed number indicating the relative values of this instance and value.</returns>
82-
public int CompareTo(object obj)
82+
public int CompareTo(object? obj)
8383
{
8484
// null is at less
8585
if (obj == null)
@@ -88,10 +88,7 @@ public int CompareTo(object obj)
8888
}
8989

9090
// convert to a proper Cidr object
91-
var other = obj as IPNetwork2;
92-
93-
// type problem if null
94-
if (other == null)
91+
if (obj is not IPNetwork2 other)
9592
{
9693
throw new ArgumentException(
9794
"The supplied parameter is an invalid type. Please supply an IPNetwork type.",

src/System.Net.IPNetwork/IPNetwork2IEquatableIPNetworkMembers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed partial class IPNetwork2 : IComparable<IPNetwork2>, IEquatable<IPN
1515
/// <param name="left">An IPNetwork to compare.</param>
1616
/// <param name="right">An other IPNetwork to compare to.</param>
1717
/// <returns>true if obj has the same value as this instance; otherwise, false.</returns>
18-
public static bool Equals(IPNetwork2 left, IPNetwork2 right)
18+
public static bool Equals(IPNetwork2? left, IPNetwork2? right)
1919
{
2020
return Compare(left, right) == 0;
2121
}
@@ -25,7 +25,7 @@ public static bool Equals(IPNetwork2 left, IPNetwork2 right)
2525
/// </summary>
2626
/// <param name="other">An IPNetwork to compare to this instance.</param>
2727
/// <returns>true if obj has the same value as this instance; otherwise, false.</returns>
28-
public bool Equals(IPNetwork2 other)
28+
public bool Equals(IPNetwork2? other)
2929
{
3030
return Equals(this, other);
3131
}
@@ -35,7 +35,7 @@ public bool Equals(IPNetwork2 other)
3535
/// </summary>
3636
/// <param name="obj">An object value to compare to this instance.</param>
3737
/// <returns>true if obj has the same value as this instance; otherwise, false.</returns>
38-
public override bool Equals(object obj)
38+
public override bool Equals(object? obj)
3939
{
4040
return Equals(this, obj as IPNetwork2);
4141
}

0 commit comments

Comments
 (0)