diff --git a/src/NexusMods.EventSourcing.Abstractions/EntityId.cs b/src/NexusMods.EventSourcing.Abstractions/EntityId.cs index 9ee1670b..b233e213 100644 --- a/src/NexusMods.EventSourcing.Abstractions/EntityId.cs +++ b/src/NexusMods.EventSourcing.Abstractions/EntityId.cs @@ -119,20 +119,11 @@ public int CompareTo(EntityId other) } } -/// -/// Interface for a strongly typed . -/// -/// -public interface IEntityId where T : IEntity -{ - -} - /// /// A typed for a specific . /// /// -public readonly struct EntityId : IEntityId where T : IEntity +public readonly struct EntityId : IEquatable>, IComparable> where T : IEntity { /// /// Creates a new instance of . @@ -198,69 +189,50 @@ public static EntityId From(ReadOnlySpan id) } return From(UInt128.Parse(id, NumberStyles.HexNumber)); } -} - -/* + /// + public bool Equals(EntityId other) + { + return Id.Equals(other.Id); + } -/// -/// A strongly typed for a specific . -/// -/// -public readonly struct EntityId where T : IEntity -{ - /// - /// Creates a new instance of . - /// - /// - public static EntityId NewId() => new(EntityId.NewId()); + /// + public int CompareTo(EntityId other) + { + return Id.CompareTo(other.Id); + } + /// + public override bool Equals(object? obj) + { + return obj is EntityId other && Equals(other); + } - /// - /// Gets the from the specified . - /// - /// - /// - public static EntityId From(UInt128 id) => new(EntityId.From(id)); + /// + public override int GetHashCode() + { + return Id.GetHashCode(); + } /// - /// Reads the from the specified . + /// Compares two s for equality. /// - /// + /// + /// /// - public static EntityId From(ReadOnlySpan data) => new(EntityId.From(data)); - + public static bool operator ==(EntityId left, EntityId right) + { + return left.Equals(right); + } /// - /// Converts the to a . + /// Compares two s for inequality. /// - /// + /// + /// /// - public static implicit operator EntityId(EntityId id) => id.Value; - - - - - - /// - /// Creates a new instance of . - /// - /// - public EntityId(EntityId id) => Value = id; - - /// - /// The underlying value. - /// - public readonly EntityId Value; - - /// - public override string ToString() + public static bool operator !=(EntityId left, EntityId right) { - return typeof(T).Name + "<" + Value.Value.ToString("X") + ">"; + return !(left == right); } - - - } - -*/