< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 57
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
.ctor(...)0%660%
Equals(...)0%660%
GetHashCode()100%110%
ToString()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Primitives/src/System/Net/DnsEndPoint.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics.CodeAnalysis;
 5using System.Net.Sockets;
 6
 7namespace System.Net
 8{
 9    public class DnsEndPoint : EndPoint
 10    {
 11        private readonly string _host;
 12        private readonly int _port;
 13        private readonly AddressFamily _family;
 14
 015        public DnsEndPoint(string host, int port) : this(host, port, AddressFamily.Unspecified) { }
 16
 017        public DnsEndPoint(string host, int port, AddressFamily addressFamily)
 018        {
 019            ArgumentException.ThrowIfNullOrEmpty(host);
 20
 021            ArgumentOutOfRangeException.ThrowIfLessThan(port, IPEndPoint.MinPort);
 022            ArgumentOutOfRangeException.ThrowIfGreaterThan(port, IPEndPoint.MaxPort);
 23
 024            if (addressFamily != AddressFamily.InterNetwork &&
 025                addressFamily != AddressFamily.InterNetworkV6 &&
 026                addressFamily != AddressFamily.Unspecified)
 027            {
 028                throw new ArgumentException(SR.net_sockets_invalid_optionValue_all, nameof(addressFamily));
 29            }
 30
 031            _host = host;
 032            _port = port;
 033            _family = addressFamily;
 034        }
 35
 36        public override bool Equals([NotNullWhen(true)] object? comparand) =>
 037            comparand is DnsEndPoint dnsComparand &&
 038            _family == dnsComparand._family &&
 039            _port == dnsComparand._port &&
 040            StringComparer.OrdinalIgnoreCase.Equals(_host, dnsComparand._host);
 41
 42        public override int GetHashCode() =>
 043            HashCode.Combine(
 044                (int)_family,
 045                _port,
 046                StringComparer.OrdinalIgnoreCase.GetHashCode(_host));
 47
 048        public override string ToString() => $"{_family}/{_host}:{_port}";
 49
 050        public string Host => _host;
 51
 052        public override AddressFamily AddressFamily => _family;
 53
 054        public int Port => _port;
 55    }
 56}
 57