Repository: microsoft/garnet
File: libs/common/Format.cs (C#)

Code before:
using Microsoft.Extensions.Logging;

#if UNIX_SOCKET
using System.Net.Sockets;
#endif

namespace Garnet.common
{
    internal static class ExtensionMethodsInternal
    {
        internal static bool IsNullOrEmpty([NotNullWhen(false)] this string s) =>
            string.IsNullOrEmpty(s);

#pragma warning disable format
        internal static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string s) =>
            string.IsNullOrWhiteSpace(s);
#pragma warning restore format
    }

    /// <summary>
    /// Formatting primitives
    /// </summary>
#pragma warning disable format
    public static class Format
    {
        static EndPoint[] defaultBindEndpoint(int port) => [new IPEndPoint(IPAddress.Any, port), new IPEndPoint(IPAddress.IPv6Any, port)];

        /// <summary>
        /// Parse address list string containing address separated by whitespace
        /// </summary>
        /// <param name="addressList">Space separated string of IP addresses</param>
        /// <param name="port">Endpoint Port</param>
        /// <param name="endpoints">List of endpoints generated from the input IPs</param>
        /// <param name="errorHostnameOrAddress">Output error if any</param>
        /// <param name="logger">Logger</param>
        /// <returns>True if parse and address validation was successful, otherwise false</returns>
        public static bool TryParseAddressList(string addressList, int port, out EndPoint[] endpoints, out string errorHostnameOrAddress, ILogger logger = null)
        {
            endpoints = null;
            errorHostnameOrAddress = null;
            // Check if input null or empty
            if (string.IsNullOrEmpty(addressList) || string.IsNullOrWhiteSpace(addressList))
            {
                endpoints = defaultBindEndpoint(port);
                return true;
            }

            var addresses = addressList.Split([',',' '], StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
            var endpointList = new List<EndPoint>();
            // Validate addresses and create endpoints
            foreach (var singleAddressOrHostname in addresses)

Review comment (suggestion):
See comment by @prvyk at https://github.com/microsoft/garnet/pull/1156#issuecomment-2771759985 re: IPv6 being potentially disabled. Perhaps use `Socket.OSSupportsIPv6`.

Code after:
using Microsoft.Extensions.Logging;

#if UNIX_SOCKET
using System.Net.Sockets;
#endif

namespace Garnet.common
{
    internal static class ExtensionMethodsInternal
    {
        internal static bool IsNullOrEmpty([NotNullWhen(false)] this string s) =>
            string.IsNullOrEmpty(s);

#pragma warning disable format
        internal static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string s) =>
            string.IsNullOrWhiteSpace(s);
#pragma warning restore format
    }

    /// <summary>
    /// Formatting primitives
    /// </summary>
#pragma warning disable format
    public static class Format
    {
        static EndPoint[] defaultBindAny(int port)
            => Socket.OSSupportsIPv6 ? [new IPEndPoint(IPAddress.Any, port), new IPEndPoint(IPAddress.IPv6Any, port)] : [new IPEndPoint(IPAddress.Any, port)];

        static EndPoint[] defaultBindLoopBack(int port)
            => Socket.OSSupportsIPv6 ? [new IPEndPoint(IPAddress.Loopback, port), new IPEndPoint(IPAddress.IPv6Loopback, port)] : [new IPEndPoint(IPAddress.Loopback, port)];

        /// <summary>
        /// Parse address list string containing address separated by whitespace
        /// </summary>
        /// <param name="addressList">Space separated string of IP addresses</param>
        /// <param name="port">Endpoint Port</param>
        /// <param name="endpoints">List of endpoints generated from the input IPs</param>
        /// <param name="errorHostnameOrAddress">Output error if any</param>
        /// <param name="logger">Logger</param>
        /// <returns>True if parse and address validation was successful, otherwise false</returns>
        public static bool TryParseAddressList(string addressList, int port, out EndPoint[] endpoints, out string errorHostnameOrAddress, ILogger logger = null)
        {
            endpoints = null;
            errorHostnameOrAddress = null;
            // Check if input null or empty
            if (string.IsNullOrEmpty(addressList) || string.IsNullOrWhiteSpace(addressList))
            {
                endpoints = defaultBindAny(port);
                return true;
            }