From c5b79b3dae73e8702caaa55998965192c8796c2f Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 21 Aug 2023 10:25:51 -0400 Subject: [PATCH] chore: Define common IUniqueID member impls in interface Taking advantage of nifty new language feats --- src/client/spark_websocket/Core/IUniqueID.cs | 22 +++++++++-------- src/client/spark_websocket/Core/UniqueID.cs | 25 +++----------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/client/spark_websocket/Core/IUniqueID.cs b/src/client/spark_websocket/Core/IUniqueID.cs index 77ec17710..006485269 100644 --- a/src/client/spark_websocket/Core/IUniqueID.cs +++ b/src/client/spark_websocket/Core/IUniqueID.cs @@ -1,13 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - namespace bts.websocket_core { // Represents a unique client, a little redundant - public interface IUniqueID { - public string ID { get; } - public int GetHashCode(); - public string ToString(); - public bool Equals(object? obj); + public interface IUniqueID : IEquatable { + string ID { get; } + + public int GetHashCode() => + ID.GetHashCode(); + + public string? ToString() => + ID; + + bool IEquatable.Equals(object? obj) => + obj is IUniqueID other && ID == other.ID; } -} \ No newline at end of file +} diff --git a/src/client/spark_websocket/Core/UniqueID.cs b/src/client/spark_websocket/Core/UniqueID.cs index 8f4c7654b..3df9e935e 100644 --- a/src/client/spark_websocket/Core/UniqueID.cs +++ b/src/client/spark_websocket/Core/UniqueID.cs @@ -1,25 +1,6 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Reflection; - namespace bts.websocket_core { // Represents a unique client, a little redundant - public class UniqueID : IUniqueID { - - public string ID { get; } - public UniqueID(string id) { - ID = id; - } - public override int GetHashCode() { - return this.ID.GetHashCode(); - } - public override string ToString() { - return this.ID.ToString() ?? ""; - } - public override bool Equals(object? obj) { - var other = obj == null ? null : obj as IUniqueID; - return other != null && (string)other.ID == ID; - } + public class UniqueID(string id) : IUniqueID { + public string ID { get; } = id; } -} \ No newline at end of file +}