Innovenergy_trunk/csharp/Lib/Utils/Net/Ip4Address.cs

40 lines
916 B
C#

using System.Net;
namespace InnovEnergy.Lib.Utils.Net;
public class Ip4Address
{
public required String? Host { get; init; }
public required UInt16? Port { get; init; }
public override String ToString() => $"{Host}:{Port}";
protected Boolean Equals(Ip4Address other)
{
return Host == other.Host
&& Port == other.Port;
}
public override Boolean Equals(Object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((Ip4Address)obj);
}
public static Boolean operator ==(Ip4Address? left, Ip4Address? right) => Equals(left, right);
public static Boolean operator !=(Ip4Address? left, Ip4Address? right) => !Equals(left, right);
public override Int32 GetHashCode() => ToString().GetHashCode();
}