public void TestWithIP() { var ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3001); var ep = EndPoint.Of(ip); Assert.AreEqual(ip, ep.GetIPEndPoint()); }
public void TestWithHostname() { var testHost = new HostEndPoint("localhost", 3001); var expectedIP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3001); var ep = EndPoint.Of(testHost); Assert.AreEqual(expectedIP, ep.GetIPEndPoint()); }
/// <summary> /// Tries to parse a string to <see cref="EndPoint"/> /// </summary> /// <param name="input">The input string.</param> /// <param name="hostEndpoint">The parsed EndPoint</param> /// <returns>true if <paramref name="input"/> converted successfully; otherwise, false.</returns> public static bool TryParse(string input, out EndPoint endpoint) { endpoint = null; if (IsIPAddress(input)) { _logger.DebugFormat("Determined that {0} is an IP.", input); if (TryParse(input, out IPEndPoint ipEndPoint)) { endpoint = EndPoint.Of(ipEndPoint); return(true); } } else { _logger.DebugFormat("Determined that {0} is not an IP address, will try to parse it as a hostname.", input); if (TryParse(input, out HostEndPoint hostEndPoint)) { endpoint = EndPoint.Of(hostEndPoint); return(true); } } return(false); }