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

lduchosal / ipnetwork / 22803352265

07 Mar 2026 05:07PM UTC coverage: 91.848% (-1.3%) from 93.118%
22803352265

push

travis-pro

web-flow
Merge pull request #383 from lduchosal/feat/v4-nullable

feat/v4-nullable

651 of 721 branches covered (90.29%)

Branch coverage included in aggregate %.

111 of 147 new or added lines in 26 files covered. (75.51%)

5 existing lines in 3 files now uncovered.

1929 of 2088 relevant lines covered (92.39%)

574342.5 hits per line

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

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

5
namespace System.Net;
6

7
using System.Diagnostics.CodeAnalysis;
8

9
/// <summary>
10
/// Regroup the tryParse functionalities.
11
/// </summary>
12
public partial class IPNetwork2
13
{
14
    /// <summary>
15
    /// 192.168.168.100 - 255.255.255.0
16
    ///
17
    /// Network   : 192.168.168.0
18
    /// Netmask   : 255.255.255.0
19
    /// Cidr      : 24
20
    /// Start     : 192.168.168.1
21
    /// End       : 192.168.168.254
22
    /// Broadcast : 192.168.168.255.
23
    /// </summary>
24
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
25
    /// <param name="netmask">A string containing a netmask to convert (255.255.255.0).</param>
26
    /// <param name="ipnetwork">When this method returns, contains the IPNetwork value equivalent of the IPAddress contained in ipaddress with the netmask corresponding to cidr, if the conversion succeeded, or null if the conversion failed. The conversion fails if the s parameter is null or Empty, is not of the correct format, or represents an invalid ip address. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
27
    /// <returns>true if ipaddress/netmask was converted successfully; otherwise, false.</returns>
28
    public static bool TryParse(string ipaddress, string netmask, [NotNullWhen(true)] out IPNetwork2? ipnetwork)
29
    {
20✔
30
        InternalParse(true, ipaddress, netmask, out IPNetwork2? ipnetwork2);
20✔
31
        bool parsed = ipnetwork2 != null;
20✔
32
        ipnetwork = ipnetwork2;
20✔
33

34
        return parsed;
20✔
35
    }
20✔
36

37
    /// <summary>
38
    /// 192.168.168.100/24
39
    ///
40
    /// Network   : 192.168.168.0
41
    /// Netmask   : 255.255.255.0
42
    /// Cidr      : 24
43
    /// Start     : 192.168.168.1
44
    /// End       : 192.168.168.254
45
    /// Broadcast : 192.168.168.255.
46
    /// </summary>
47
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
48
    /// <param name="cidr">A byte representing the netmask in cidr format (/24).</param>
49
    /// <param name="ipnetwork">When this method returns, contains the IPNetwork value equivalent of the IPAddress contained in ipaddress with the netmask corresponding to cidr, if the conversion succeeded, or null if the conversion failed. The conversion fails if the s parameter is null or Empty, is not of the correct format, or represents an invalid ip address. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
50
    /// <returns>true if ipaddress/cidr was converted successfully; otherwise, false.</returns>
51
    public static bool TryParse(string ipaddress, byte cidr, [NotNullWhen(true)] out IPNetwork2? ipnetwork)
52
    {
70✔
53
        InternalParse(true, ipaddress, cidr, out IPNetwork2? ipnetwork2);
70✔
54
        bool parsed = ipnetwork2 != null;
70✔
55
        ipnetwork = ipnetwork2;
70✔
56

57
        return parsed;
70✔
58
    }
70✔
59

60
    /// <summary>
61
    /// 192.168.0.1/24
62
    /// 192.168.0.1 255.255.255.0
63
    ///
64
    /// Network   : 192.168.0.0
65
    /// Netmask   : 255.255.255.0
66
    /// Cidr      : 24
67
    /// Start     : 192.168.0.1
68
    /// End       : 192.168.0.254
69
    /// Broadcast : 192.168.0.255.
70
    /// </summary>
71
    /// <param name="network">A string containing an ip network to convert.</param>
72
    /// <param name="ipnetwork">When this method returns, contains the IPNetwork value equivalent of the IPAddress contained in ipaddress with the netmask corresponding to cidr, if the conversion succeeded, or null if the conversion failed. The conversion fails if the s parameter is null or Empty, is not of the correct format, or represents an invalid ip address. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
73
    /// <returns>true if network was converted successfully; otherwise, false.</returns>
74
    public static bool TryParse(string network, [NotNullWhen(true)] out IPNetwork2? ipnetwork)
75
    {
46✔
76
        bool parsed = InternalParse(true, network, CidrGuess.ClassFull, sanitize: true, out ipnetwork);
46✔
77
        return parsed;
46✔
78
    }
46✔
79

80
    /// <summary>
81
    /// 192.168.0.1/24
82
    /// 192.168.0.1 255.255.255.0
83
    ///
84
    /// Network   : 192.168.0.0
85
    /// Netmask   : 255.255.255.0
86
    /// Cidr      : 24
87
    /// Start     : 192.168.0.1
88
    /// End       : 192.168.0.254
89
    /// Broadcast : 192.168.0.255.
90
    /// </summary>
91
    /// <param name="network">A string containing an ip network to convert.</param>
92
    /// <param name="sanitize">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>
93
    /// <param name="ipnetwork">When this method returns, contains the IPNetwork value equivalent of the IPAddress contained in ipaddress with the netmask corresponding to cidr, if the conversion succeeded, or null if the conversion failed. The conversion fails if the s parameter is null or Empty, is not of the correct format, or represents an invalid ip address. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
94
    /// <returns>true if network was converted successfully; otherwise, false.</returns>
95
    public static bool TryParse(string network, bool sanitize, [NotNullWhen(true)] out IPNetwork2? ipnetwork)
96
    {
14✔
97
        bool parsed = InternalParse(true, network, CidrGuess.ClassFull, sanitize, out ipnetwork);
14✔
98
        return parsed;
14✔
99
    }
14✔
100

101
    /// <summary>
102
    /// 192.168.0.1/24
103
    /// 192.168.0.1 255.255.255.0
104
    ///
105
    /// Network   : 192.168.0.0
106
    /// Netmask   : 255.255.255.0
107
    /// Cidr      : 24
108
    /// Start     : 192.168.0.1
109
    /// End       : 192.168.0.254
110
    /// Broadcast : 192.168.0.255.
111
    /// </summary>
112
    /// <param name="ipaddress">An IPAddress to convert.</param>
113
    /// <param name="netmask">An IPAddress to be used as netmask to convert.</param>
114
    /// <param name="ipnetwork">When this method returns, contains the IPNetwork value equivalent of the IPAddress contained in ipaddress with the netmask corresponding to cidr, if the conversion succeeded, or null if the conversion failed. The conversion fails if the s parameter is null or Empty, is not of the correct format, or represents an invalid ip address. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
115
    /// <returns>true if network was converted successfully; otherwise, false.</returns>
116
    public static bool TryParse(IPAddress ipaddress, IPAddress netmask, [NotNullWhen(true)] out IPNetwork2? ipnetwork)
117
    {
4✔
118
        bool parsed = InternalParse(true, ipaddress, netmask, out ipnetwork);
4✔
119
        return parsed;
4✔
120
    }
4✔
121

122
    /// <summary>
123
    /// 192.168.0.1/24
124
    /// 192.168.0.1 255.255.255.0
125
    ///
126
    /// Network   : 192.168.0.0
127
    /// Netmask   : 255.255.255.0
128
    /// Cidr      : 24
129
    /// Start     : 192.168.0.1
130
    /// End       : 192.168.0.254
131
    /// Broadcast : 192.168.0.255.
132
    /// </summary>
133
    /// <param name="network">A string containing an ip network to convert.</param>
134
    /// <param name="cidrGuess">A ICidrGuess implementation that will be used to guess CIDR during conversion.</param>
135
    /// <param name="ipnetwork">When this method returns, contains the IPNetwork value equivalent of the IPAddress contained in ipaddress with the netmask corresponding to cidr, if the conversion succeeded, or null if the conversion failed. The conversion fails if the s parameter is null or Empty, is not of the correct format, or represents an invalid ip address. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
136
    /// <returns>true if network was converted successfully; otherwise, false.</returns>
137
    public static bool TryParse(string network, ICidrGuess cidrGuess, [NotNullWhen(true)] out IPNetwork2? ipnetwork)
138
    {
3✔
139
        bool parsed = InternalParse(true, network, cidrGuess, true, out ipnetwork);
3✔
140
        return parsed;
3✔
141
    }
3✔
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="sanitize">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
    /// <param name="ipnetwork">When this method returns, contains the IPNetwork value equivalent of the IPAddress contained in ipaddress with the netmask corresponding to cidr, if the conversion succeeded, or null if the conversion failed. The conversion fails if the s parameter is null or Empty, is not of the correct format, or represents an invalid ip address. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
158
    /// <returns>true if network was converted successfully; otherwise, false.</returns>
159
    public static bool TryParse(string network, ICidrGuess cidrGuess, bool sanitize, [NotNullWhen(true)] out IPNetwork2? ipnetwork)
160
    {
×
NEW
161
        bool parsed = InternalParse(true, network, cidrGuess, sanitize, out ipnetwork);
×
162
        return parsed;
×
163
    }
×
164
}
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

© 2026 Coveralls, Inc