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

lduchosal / ipnetwork / 960

15 May 2026 07:18AM UTC coverage: 0.0% (-94.1%) from 94.053%
960

Pull #411

appveyor

web-flow
Merge ef6b054ce into 4cec191ae
Pull Request #411: Bump MSTest.TestFramework from 4.2.2 to 4.2.3

0 of 2438 relevant lines covered (0.0%)

0.0 hits per line

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

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

5
namespace System.Net;
6

7
using System.Collections;
8
using System.Collections.Generic;
9
using System.Numerics;
10

11
/// <summary>
12
/// Represents a collection of IP addresses within a specific IP network.
13
/// </summary>
14
public class IPAddressCollection : IEnumerable<IPAddress>, IEnumerator<IPAddress>
15
{
16
    private readonly IPNetwork2 ipnetwork;
17
    private readonly Filter filter;
18
    private BigInteger enumerator;
19

20
    /// <summary>
21
    /// Initializes a new instance of the <see cref="IPAddressCollection"/> class.
22
    /// </summary>
23
    /// <param name="ipnetwork">The network.</param>
24
    /// <param name="filter">The filter.</param>
25
    internal IPAddressCollection(IPNetwork2 ipnetwork, Filter filter)
×
26
    {
×
27
        this.ipnetwork = ipnetwork;
×
28
        this.filter = filter;
×
29
        this.Reset();
×
30
    }
×
31

32
    /// <summary>
33
    /// Gets the count of IP addresses within the network.
34
    /// </summary>
35
    /// <value>
36
    /// The count of IP addresses within the network.
37
    /// </value>
38
    public BigInteger Count
39
    {
40
        get
41
        {
×
42
            BigInteger count = this.ipnetwork.Total;
×
43
            if (this.filter == Filter.Usable)
×
44
            {
×
45
                count -= 2;
×
46
            }
×
47

48
            if (count < 0)
×
49
            {
×
50
                count = 0;
×
51
            }
×
52

53
            return count;
×
54
        }
×
55
    }
56

57
    /// <summary>
58
    /// Gets the IP address corresponding to the given index from the IPNetwork collection.
59
    /// </summary>
60
    /// <param name="i">The index of the IP address to retrieve.</param>
61
    /// <returns>The IP address corresponding to the given index.</returns>
62
    /// <exception cref="ArgumentOutOfRangeException">Thrown when the given index is greater than or equal to the Count property of the IPNetwork collection.</exception>
63
    public IPAddress this[BigInteger i]
64
    {
65
        get
66
        {
×
67
            if (i >= this.Count)
×
68
            {
×
69
                throw new ArgumentOutOfRangeException(nameof(i));
×
70
            }
71

72
            byte width = this.ipnetwork.AddressFamily == Sockets.AddressFamily.InterNetwork ? (byte)32 : (byte)128;
×
73
            IPNetworkCollection ipn = this.ipnetwork.Subnet(width);
×
74

75
            BigInteger index = i;
×
76
            if (this.filter == Filter.Usable)
×
77
            {
×
78
                index++;
×
79
            }
×
80

81
            return ipn[index].Network;
×
82
        }
×
83
    }
84

85
    /// <summary>
86
    /// Gets the current <see cref="IPAddress"/> from the collection.
87
    /// </summary>
88
    /// <returns>The current <see cref="IPAddress"/>.</returns>
89
    public IPAddress Current
90
    {
91
        get
92
        {
×
93
            return this[this.enumerator];
×
94
        }
×
95
    }
96

97
    /// <inheritdoc/>
98
    object IEnumerator.Current
99
    {
100
        get
101
        {
×
102
            return this.Current;
×
103
        }
×
104
    }
105

106
    /// <inheritdoc />
107
    public bool MoveNext()
108
    {
×
109
        this.enumerator++;
×
110
        if (this.enumerator >= this.Count)
×
111
        {
×
112
            return false;
×
113
        }
114

115
        return true;
×
116
    }
×
117

118
    /// <inheritdoc />
119
    public void Reset()
120
    {
×
121
        this.enumerator = -1;
×
122
    }
×
123

124
    /// <inheritdoc />
125
    public void Dispose()
126
    {
×
127
        Dispose(true);
×
128
        GC.SuppressFinalize(this);
×
129
    }
×
130

131
    /// <summary>
132
    /// Dispose instance
133
    /// </summary>
134
    /// <param name="disposing"></param>
135
    protected virtual void Dispose(bool disposing)
136
    {
×
137
        // Cleanup
138
    }
×
139

140
    /// <inheritdoc/>
141
    IEnumerator<IPAddress> IEnumerable<IPAddress>.GetEnumerator()
142
    {
×
143
        return new Enumerator(this);
×
144
    }
×
145

146
    /// <inheritdoc/>
147
    IEnumerator IEnumerable.GetEnumerator()
148
    {
×
149
        return new Enumerator(this);
×
150
    }
×
151

152
    private struct Enumerator : IEnumerator<IPAddress>
153
    {
154
        private readonly IPAddressCollection collection;
155
        private BigInteger enumerator;
156

157
        object IEnumerator.Current
158
        {
159
            get
160
            {
×
161
                return this.Current;
×
162
            }
×
163
        }
164

165
        public IPAddress Current
166
        {
167
            get
168
            {
×
169
                return this.collection[this.enumerator];
×
170
            }
×
171
        }
172

173
        public void Dispose()
174
        {
×
175
            // nothing to dispose
176
        }
×
177

178
        public bool MoveNext()
179
        {
×
180
            this.enumerator++;
×
181
            if (this.enumerator >= this.collection.Count)
×
182
            {
×
183
                return false;
×
184
            }
185

186
            return true;
×
187
        }
×
188

189
        public void Reset()
190
        {
×
191
            this.enumerator = -1;
×
192
        }
×
193

194
        public Enumerator(IPAddressCollection collection)
195
        {
×
196
            this.collection = collection;
×
197
            this.enumerator = -1;
×
198
        }
×
199
    }
200
}
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