mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 01:18:46 +00:00
🚚 Move EndPointExtensions to child namespace
This commit is contained in:
parent
9db0249790
commit
2ae1c3e249
@ -1,43 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace X10D
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for <see cref="EndPoint" /> and derived types.
|
|
||||||
/// </summary>
|
|
||||||
public static class EndPointExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the endpoint hostname.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="endPoint">The endpoint whose hostname to get.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// Returns a <see cref="string" /> representing the hostname, which may be an IP or a DNS, or empty
|
|
||||||
/// string on failure.
|
|
||||||
/// </returns>
|
|
||||||
public static string GetHost(this EndPoint endPoint)
|
|
||||||
{
|
|
||||||
return endPoint switch
|
|
||||||
{
|
|
||||||
IPEndPoint ip => ip.Address.ToString(),
|
|
||||||
DnsEndPoint dns => dns.Host,
|
|
||||||
var _ => string.Empty,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the endpoint port.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="endPoint">The endpoint whose port to get.</param>
|
|
||||||
/// <returns>Returns an <see cref="int" /> representing the port, or 0 on failure.</returns>
|
|
||||||
public static int GetPort(this EndPoint endPoint)
|
|
||||||
{
|
|
||||||
return endPoint switch
|
|
||||||
{
|
|
||||||
IPEndPoint ip => ip.Port,
|
|
||||||
DnsEndPoint dns => dns.Port,
|
|
||||||
var _ => 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
55
X10D/src/EndPointExtensions/EndPointExtensions.cs
Normal file
55
X10D/src/EndPointExtensions/EndPointExtensions.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace X10D.EndPointExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for <see cref="EndPoint" /> and derived types.
|
||||||
|
/// </summary>
|
||||||
|
public static class EndPointExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the hostname for the current <see cref="System.Net.EndPoint" />.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="endPoint">The endpoint whose hostname to get.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// <see cref="IPEndPoint.Address" /> if <paramref name="endPoint" /> is <see cref="IPEndPoint" />
|
||||||
|
/// -or-
|
||||||
|
/// <see cref="DnsEndPoint.Host" /> if <paramref name="endPoint" /> is <see cref="DnsEndPoint" />
|
||||||
|
/// -or-
|
||||||
|
/// <see cref="string.Empty" /> otherwise.
|
||||||
|
/// </returns>
|
||||||
|
[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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the port number for the current <see cref="System.Net.EndPoint" />.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="endPoint">The endpoint whose port number to get.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// <see cref="IPEndPoint.Port" /> if <paramref name="endPoint" /> is <see cref="IPEndPoint" />
|
||||||
|
/// -or-
|
||||||
|
/// <see cref="DnsEndPoint.Port" /> if <paramref name="endPoint" /> is <see cref="DnsEndPoint" />
|
||||||
|
/// -or-
|
||||||
|
/// <c>0</c> otherwise.
|
||||||
|
/// </returns>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static int GetPort(this EndPoint endPoint)
|
||||||
|
{
|
||||||
|
return endPoint switch
|
||||||
|
{
|
||||||
|
IPEndPoint ip => ip.Port,
|
||||||
|
DnsEndPoint dns => dns.Port,
|
||||||
|
var _ => 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user