From 2ae1c3e249fc2818285faf2d62568c698b9ef319 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 20 Jan 2021 22:13:40 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Move=20EndPointExtensions=20to?= =?UTF-8?q?=20child=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- X10D/src/EndPointExtensions.cs | 43 --------------- .../EndPointExtensions/EndPointExtensions.cs | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 43 deletions(-) delete mode 100644 X10D/src/EndPointExtensions.cs create mode 100644 X10D/src/EndPointExtensions/EndPointExtensions.cs diff --git a/X10D/src/EndPointExtensions.cs b/X10D/src/EndPointExtensions.cs deleted file mode 100644 index 01fd9e4..0000000 --- a/X10D/src/EndPointExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Net; - -namespace X10D -{ - /// - /// 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) - { - return endPoint switch - { - IPEndPoint ip => ip.Address.ToString(), - DnsEndPoint dns => dns.Host, - var _ => 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) - { - return endPoint switch - { - IPEndPoint ip => ip.Port, - DnsEndPoint dns => dns.Port, - var _ => 0, - }; - } - } -} diff --git a/X10D/src/EndPointExtensions/EndPointExtensions.cs b/X10D/src/EndPointExtensions/EndPointExtensions.cs new file mode 100644 index 0000000..8093302 --- /dev/null +++ b/X10D/src/EndPointExtensions/EndPointExtensions.cs @@ -0,0 +1,55 @@ +using System.Net; +using System.Runtime.CompilerServices; + +namespace X10D.EndPointExtensions +{ + /// + /// Extension methods for and derived types. + /// + public static class EndPointExtensions + { + /// + /// Returns the hostname for the current . + /// + /// The endpoint whose hostname to get. + /// + /// if is + /// -or- + /// if is + /// -or- + /// otherwise. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string GetHost(this EndPoint endPoint) + { + return endPoint switch + { + IPEndPoint ip => ip.Address.ToString(), + DnsEndPoint dns => dns.Host, + var _ => string.Empty + }; + } + + /// + /// Returns the port number for the current . + /// + /// The endpoint whose port number to get. + /// + /// if is + /// -or- + /// if is + /// -or- + /// 0 otherwise. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetPort(this EndPoint endPoint) + { + return endPoint switch + { + IPEndPoint ip => ip.Port, + DnsEndPoint dns => dns.Port, + var _ => 0 + }; + } + } +}