Ejemplo n.º 1
0
        public static IPHost Parse(string host)
        {
            if (!string.IsNullOrEmpty(host) && IPHost.TryParse(host, out IPHost res))
            {
                return(res);
            }

            throw new InvalidCastException("Host does not contain a valid value. {host}");
        }
Ejemplo n.º 2
0
        public static IPHost Parse(string host, AddressFamily family)
        {
            if (!string.IsNullOrEmpty(host) && IPHost.TryParse(host, out IPHost res))
            {
                if (family == AddressFamily.InterNetwork)
                {
                    res.Remove(AddressFamily.InterNetworkV6);
                }
                else
                {
                    res.Remove(AddressFamily.InterNetwork);
                }

                return(res);
            }

            throw new InvalidCastException("Host does not contain a valid value. {host}");
        }