diff --git a/X10D/EndPointExtensions.cs b/X10D/EndPointExtensions.cs new file mode 100644 index 0000000..99017ba --- /dev/null +++ b/X10D/EndPointExtensions.cs @@ -0,0 +1,42 @@ +namespace X10D +{ + #region Using Directives + + using System; + using System.Net; + + #endregion + + /// + /// A set of extension methods for and derived types. + /// + public static class EndPointExtensions + { + /// + /// Gets the endpoint hostname. + /// + /// The endpoint whose hostname to get. + /// Returns a representing the hostname, which may be an IP or a DNS, or empty + /// string on failure. + public static string GetHost(this EndPoint endPoint) => + endPoint switch + { + IPEndPoint ip => ip.Address.ToString(), + DnsEndPoint dns => dns.Host, + _ => String.Empty + }; + + /// + /// Gets the endpoint port. + /// + /// The endpoint whose port to get. + /// Returns an representing the port, or 0 on failure. + public static int GetPort(this EndPoint endPoint) => + endPoint switch + { + IPEndPoint ip => ip.Port, + DnsEndPoint dns => dns.Port, + _ => 0 + }; + } +} diff --git a/X10D/X10D.csproj b/X10D/X10D.csproj index 841cc56..4c89f47 100644 --- a/X10D/X10D.csproj +++ b/X10D/X10D.csproj @@ -50,6 +50,7 @@ +