• 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/IPNetwork2IComparableIPNetworkMembers.cs
1
// <copyright file="IPNetwork2IComparableIPNetworkMembers.cs" company="IPNetwork">
2
// Copyright (c) IPNetwork. All rights reserved.
3
// </copyright>
4

5
namespace System.Net;
6

7
/// <summary>
8
/// IComparable.
9
/// </summary>
10
public sealed partial class IPNetwork2
11
{
12
    /// <summary>
13
    /// Compares two IPNetwork2 instances.
14
    /// </summary>
15
    /// <param name="left">The first IPNetwork2 instance to compare.</param>
16
    /// <param name="right">The second IPNetwork2 instance to compare.</param>
17
    /// <returns>
18
    /// A value indicating the relative order of the two IPNetwork2 instances.
19
    /// Zero if the instances are equal.
20
    /// A negative value if <paramref name="left"/> is less than <paramref name="right"/>.
21
    /// A positive value if <paramref name="left"/> is greater than <paramref name="right"/>.
22
    /// </returns>
23
    public static int Compare(IPNetwork2? left, IPNetwork2? right)
24
    {
×
25
        // two null IPNetworks are equal
26
        if (left is null && right is null)
×
27
        {
×
28
            return 0;
×
29
        }
30

31
        // two same IPNetworks are equal
32
        if (ReferenceEquals(left, right))
×
33
        {
×
34
            return 0;
×
35
        }
36

37
        // null is always sorted first
38
        if (left is null)
×
39
        {
×
40
            return -1;
×
41
        }
42

43
        if (right is null)
×
44
        {
×
45
            return 1;
×
46
        }
47

48
        // first test family
49
        int result = left.family.CompareTo(right.family);
×
50
        if (result != 0)
×
51
        {
×
52
            return result;
×
53
        }
54

55
        // second test the network
56
        result = left.InternalNetwork.CompareTo(right.InternalNetwork);
×
57
        if (result != 0)
×
58
        {
×
59
            return result;
×
60
        }
61

62
        // then test the cidr
63
        result = (left.cidr * -1).CompareTo((right.cidr * -1));
×
64
        return result;
×
65
    }
×
66

67
    /// <summary>
68
    /// Compare two ipnetworks.
69
    /// </summary>
70
    /// <param name="other">The other network to compare to.</param>
71
    /// <returns>A signed number indicating the relative values of this instance and value.</returns>
72
    public int CompareTo(IPNetwork2? other)
73
    {
×
74
        return Compare(this, other);
×
75
    }
×
76

77
    /// <summary>
78
    /// Compare two ipnetworks.
79
    /// </summary>
80
    /// <param name="obj">The other object to compare to.</param>
81
    /// <returns>A signed number indicating the relative values of this instance and value.</returns>
82
    public int CompareTo(object? obj)
83
    {
×
84
        // null is at less
85
        if (obj == null)
×
86
        {
×
87
            return 1;
×
88
        }
89

90
        // convert to a proper Cidr object
91
        if (obj is not IPNetwork2 other)
×
92
        {
×
93
            throw new ArgumentException(
×
94
                "The supplied parameter is an invalid type. Please supply an IPNetwork type.",
×
95
                nameof(obj));
×
96
        }
97

98
        // perform the comparision
99
        return this.CompareTo(other);
×
100
    }
×
101
}
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