• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lduchosal / ipnetwork / 809

17 Aug 2025 08:25AM UTC coverage: 93.223% (-1.0%) from 94.226%
809

push

appveyor

web-flow
Chore: cleanup, breaking changes, enum, tryparse, exception, static ListIPAddress (#363)

* Chore: huge cleanup, enum, tryparse, exception, static ListIPAddress, important changes : IPNetwork comparison and sort order have change to reflect expected behavoir
* Fix: obsolete enums
* Fix: network sorting and member comparison
* Chore: upgrade version number 3.3

1802 of 1933 relevant lines covered (93.22%)

726934.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.0
/src/System.Net.IPNetwork/IPNetwork2Parse.cs
1
// <copyright file="IPNetwork2Parse.cs" company="IPNetwork">
2
// Copyright (c) IPNetwork. All rights reserved.
3
// </copyright>
4

5
namespace System.Net;
6

7
/// <summary>
8
/// the parse methods.
9
/// </summary>
10
public partial class IPNetwork2
11
{
12
    /// <summary>
13
    /// 192.168.168.100 - 255.255.255.0
14
    ///
15
    /// ```
16
    /// Network   : 192.168.168.0
17
    /// Netmask   : 255.255.255.0
18
    /// Cidr      : 24
19
    /// Start     : 192.168.168.1
20
    /// End       : 192.168.168.254
21
    /// Broadcast : 192.168.168.255
22
    /// ```.
23
    ///
24
    /// </summary>
25
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
26
    /// <param name="netmask">A string representing a netmask in std format (255.255.255.0).</param>
27
    /// <returns>An IPNetwork equivalent to the network contained in ipaddress/netmask.</returns>
28
    public static IPNetwork2 Parse(string ipaddress, string netmask)
29
    {
16✔
30
        InternalParse(false, ipaddress, netmask, out IPNetwork2 ipnetwork);
16✔
31
        return ipnetwork;
3✔
32
    }
3✔
33

34
    /// <summary>
35
    /// 192.168.168.100/24
36
    ///
37
    /// Network   : 192.168.168.0
38
    /// Netmask   : 255.255.255.0
39
    /// Cidr      : 24
40
    /// Start     : 192.168.168.1
41
    /// End       : 192.168.168.254
42
    /// Broadcast : 192.168.168.255.
43
    /// </summary>
44
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
45
    /// <param name="cidr">A byte representing the netmask in cidr format (/24).</param>
46
    /// <returns>An IPNetwork equivalent to the network contained in ipaddress/cidr.</returns>
47
    public static IPNetwork2 Parse(string ipaddress, byte cidr)
48
    {
30✔
49
        InternalParse(false, ipaddress, cidr, out IPNetwork2 ipnetwork);
30✔
50
        return ipnetwork;
26✔
51
    }
26✔
52

53
    /// <summary>
54
    /// 192.168.168.100 255.255.255.0
55
    ///
56
    /// Network   : 192.168.168.0
57
    /// Netmask   : 255.255.255.0
58
    /// Cidr      : 24
59
    /// Start     : 192.168.168.1
60
    /// End       : 192.168.168.254
61
    /// Broadcast : 192.168.168.255.
62
    /// </summary>
63
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
64
    /// <param name="netmask">A netmask to be used to create the IPNetwork.</param>
65
    /// <returns>An IPNetwork equivalent to the network contained in ipaddress/netmask.</returns>
66
    public static IPNetwork2 Parse(IPAddress ipaddress, IPAddress netmask)
67
    {
6✔
68
        InternalParse(false, ipaddress, netmask, out IPNetwork2 ipnetwork);
6✔
69
        return ipnetwork;
2✔
70
    }
2✔
71

72
    /// <summary>
73
    /// 192.168.0.1/24
74
    /// 192.168.0.1 255.255.255.0
75
    ///
76
    /// Network   : 192.168.0.0
77
    /// Netmask   : 255.255.255.0
78
    /// Cidr      : 24
79
    /// Start     : 192.168.0.1
80
    /// End       : 192.168.0.254
81
    /// Broadcast : 192.168.0.255.
82
    /// </summary>
83
    /// <param name="network">A string containing an ip network to convert.</param>
84
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
85
    public static IPNetwork2 Parse(string network)
86
    {
4,000,943✔
87
        bool parsed = InternalParse(false, network, CidrGuess.ClassFull, true, out IPNetwork2 ipnetwork);
4,000,943✔
88
        if (!parsed)
4,000,936✔
89
        {
×
90
            throw new ArgumentException(nameof(network));
×
91
        }
92
        return ipnetwork;
4,000,936✔
93
    }
4,000,936✔
94

95
    /// <summary>
96
    /// 192.168.0.1/24
97
    /// 192.168.0.1 255.255.255.0
98
    ///
99
    /// Network   : 192.168.0.0
100
    /// Netmask   : 255.255.255.0
101
    /// Cidr      : 24
102
    /// Start     : 192.168.0.1
103
    /// End       : 192.168.0.254
104
    /// Broadcast : 192.168.0.255.
105
    /// </summary>
106
    /// <param name="network">A string containing an ip network to convert.</param>
107
    /// <param name="sanitanize">If true, removes invalid characters and normalizes whitespace from the network string, keeping only valid network address characters (0-9, a-f, A-F, ., /, :, and spaces).</param>
108
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
109
    public static IPNetwork2 Parse(string network, bool sanitanize)
110
    {
×
111
        bool parsed = InternalParse(false, network, CidrGuess.ClassFull, sanitanize, out IPNetwork2 ipnetwork);
×
112
        if (!parsed)
×
113
        {
×
114
            throw new ArgumentException(nameof(network));
×
115
        }
116
        return ipnetwork;
×
117
    }
×
118

119
    /// <summary>
120
    /// 192.168.0.1/24
121
    /// 192.168.0.1 255.255.255.0
122
    ///
123
    /// Network   : 192.168.0.0
124
    /// Netmask   : 255.255.255.0
125
    /// Cidr      : 24
126
    /// Start     : 192.168.0.1
127
    /// End       : 192.168.0.254
128
    /// Broadcast : 192.168.0.255.
129
    /// </summary>
130
    /// <param name="network">A string containing an ip network to convert.</param>
131
    /// <param name="cidrGuess">A ICidrGuess implementation that will be used to guess CIDR during conversion.</param>
132
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
133
    public static IPNetwork2 Parse(string network, ICidrGuess cidrGuess)
134
    {
16✔
135
        bool parsed = InternalParse(false, network, cidrGuess, true, out IPNetwork2 ipnetwork);
16✔
136
        if (!parsed)
16✔
137
        {
×
138
            throw new ArgumentException(nameof(network));
×
139
        }
140
        return ipnetwork;
16✔
141
    }
16✔
142

143
    /// <summary>
144
    /// 192.168.0.1/24
145
    /// 192.168.0.1 255.255.255.0
146
    ///
147
    /// Network   : 192.168.0.0
148
    /// Netmask   : 255.255.255.0
149
    /// Cidr      : 24
150
    /// Start     : 192.168.0.1
151
    /// End       : 192.168.0.254
152
    /// Broadcast : 192.168.0.255.
153
    /// </summary>
154
    /// <param name="network">A string containing an ip network to convert.</param>
155
    /// <param name="cidrGuess">A ICidrGuess implementation that will be used to guess CIDR during conversion.</param>
156
    /// <param name="sanitanize">If true, removes invalid characters and normalizes whitespace from the network string, keeping only valid network address characters (0-9, a-f, A-F, ., /, :, and spaces).</param>
157
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
158
    public static IPNetwork2 Parse(string network, ICidrGuess cidrGuess, bool sanitanize)
159
    {
×
160
        bool parsed = InternalParse(false, network, cidrGuess, sanitanize, out IPNetwork2 ipnetwork);
×
161
        if (!parsed)
×
162
        {
×
163
            throw new ArgumentException(nameof(network));
×
164
        }
165
        return ipnetwork;
×
166
    }
×
167
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc