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

lduchosal / ipnetwork / 581

02 Jun 2023 08:29AM CUT coverage: 94.615%. Remained the same
581

push

appveyor

web-flow
Merge pull request #271 from lduchosal/dependabot/nuget/Microsoft.CodeCoverage-17.6.1

Build(deps): Bump Microsoft.CodeCoverage from 17.6.0 to 17.6.1

1599 of 1690 relevant lines covered (94.62%)

1185099.52 hits per line

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

92.21
/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
    public enum FilterEnum
12
    {
13
        All,
14
        Usable,
15
    }
16

17
    /// <summary>
18
    /// A collection of IP Adresses
19
    /// </summary>
20
    public class IPAddressCollection : IEnumerable<IPAddress>, IEnumerator<IPAddress>
21
    {
22
        private readonly IPNetwork _ipnetwork;
23
        private readonly FilterEnum _filter;
24
        private BigInteger _enumerator;
25

26
        internal IPAddressCollection(IPNetwork ipnetwork, FilterEnum filter)
32✔
27
        {
32✔
28
            this._ipnetwork = ipnetwork;
32✔
29
            this._filter = filter;
32✔
30
            this.Reset();
32✔
31
        }
32✔
32

33
        #region Count, Array, Enumerator
34
        public BigInteger Count
35
        {
36
            get
37
            {
266✔
38
                BigInteger count = this._ipnetwork.Total;
266✔
39
                if (this._filter == FilterEnum.Usable)
266✔
40
                {
27✔
41
                    count -= 2;
27✔
42
                }
27✔
43

44
                if (count < 0)
266✔
45
                {
1✔
46
                    count = 0;
1✔
47
                }
1✔
48

49
                return count;
266✔
50
            }
266✔
51
        }
52

53
        public IPAddress this[BigInteger i]
54
        {
55
            get
56
            {
132✔
57
                if (i >= this.Count)
132✔
58
                {
6✔
59
                    throw new ArgumentOutOfRangeException("i");
6✔
60
                }
61

62
                byte width = this._ipnetwork.AddressFamily == Sockets.AddressFamily.InterNetwork ? (byte)32 : (byte)128;
126✔
63
                IPNetworkCollection ipn = this._ipnetwork.Subnet(width);
126✔
64

65
                BigInteger index = i;
126✔
66
                if (this._filter == FilterEnum.Usable)
126✔
67
                {
18✔
68
                    index++;
18✔
69
                }
18✔
70

71
                return ipn[index].Network;
126✔
72
            }
126✔
73
        }
74

75
        #endregion
76

77
        #region Legacy Enumeration
78
        public IPAddress Current
79
        {
80
            get
81
            {
64✔
82
                return this[this._enumerator];
64✔
83
            }
60✔
84
        }
85

86
        object IEnumerator.Current
87
        {
88
            get
89
            {
14✔
90
                return this.Current;
14✔
91
            }
12✔
92
        }
93

94
        public bool MoveNext()
95
        {
104✔
96
            this._enumerator++;
104✔
97
            if (this._enumerator >= this.Count)
104✔
98
            {
20✔
99
                return false;
20✔
100
            }
101

102
            return true;
84✔
103
        }
104✔
104

105
        public void Reset()
106
        {
42✔
107
            this._enumerator = -1;
42✔
108
        }
42✔
109

110
        public void Dispose()
111
        {
25✔
112
            // nothing to dispose
113
        }
25✔
114
        #endregion
115

116
        #region Enumeration
117
        IEnumerator<IPAddress> IEnumerable<IPAddress>.GetEnumerator()
118
        {
3✔
119
            return new Enumerator(this);
3✔
120
        }
3✔
121

122
        IEnumerator IEnumerable.GetEnumerator()
123
        {
1✔
124
            return new Enumerator(this);
1✔
125
        }
1✔
126

127
        private struct Enumerator : IEnumerator<IPAddress>
128
        {
129
            private readonly IPAddressCollection _collection;
130
            private BigInteger _enumerator;
131

132
            object IEnumerator.Current
133
            {
134
                get
135
                {
×
136
                    return this.Current;
×
137
                }
×
138
            }
139

140
            public IPAddress Current
141
            {
142
                get
143
                {
22✔
144
                    return this._collection[this._enumerator];
22✔
145
                }
22✔
146
            }
147

148
            public void Dispose()
149
            {
3✔
150
                // nothing to dispose
151
            }
3✔
152

153
            public bool MoveNext()
154
            {
25✔
155
                this._enumerator++;
25✔
156
                if (this._enumerator >= this._collection.Count)
25✔
157
                {
3✔
158
                    return false;
3✔
159
                }
160

161
                return true;
22✔
162
            }
25✔
163

164
            public void Reset()
165
            {
×
166
                this._enumerator = -1;
×
167
            }
×
168

169
            public Enumerator(IPAddressCollection collection)
170
            {
4✔
171
                this._collection = collection;
4✔
172
                this._enumerator = -1;
4✔
173
            }
4✔
174
        }
175
        #endregion
176
    }
177
}
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