< Summary

Information
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 38
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetIPAddress(...)100%110%
GetPort(...)0%220%
GetIPEndPoint(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/Common/src/System/Net/SocketAddressExtensions.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;
 5using System.Net;
 6
 7namespace System.Net.Sockets
 8{
 9    internal static partial class SocketAddressExtensions
 10    {
 011        public static IPAddress GetIPAddress(this SocketAddress socketAddress) => IPEndPointExtensions.GetIPAddress(sock
 12        public static int GetPort(this SocketAddress socketAddress)
 013        {
 014            Debug.Assert(socketAddress.Family == AddressFamily.InterNetwork || socketAddress.Family == AddressFamily.Int
 015            return (int)SocketAddressPal.GetPort(socketAddress.Buffer.Span);
 016        }
 17
 18        public static IPEndPoint GetIPEndPoint(this SocketAddress socketAddress)
 019        {
 020            return new IPEndPoint(socketAddress.GetIPAddress(), socketAddress.GetPort());
 021        }
 22
 23        public static bool Equals(this SocketAddress socketAddress, EndPoint? endPoint)
 24        {
 25            if (socketAddress.Family == endPoint?.AddressFamily && endPoint is IPEndPoint ipe)
 26            {
 27                return ipe.Equals(socketAddress.Buffer.Span);
 28            }
 29
 30            // We could serialize other EndPoints and compare socket addresses.
 31            // But that would do two allocations and is probably as expensive as
 32            // allocating new EndPoint.
 33            // This may change if https://github.com/dotnet/runtime/issues/78993 is done
 34            return false;
 35        }
 36    }
 37}
 38