| | | 1 | | namespace Enjoy.Domain.Shared.Primitives; |
| | | 2 | | |
| | | 3 | | public abstract class Entity : IEquatable<Entity> |
| | | 4 | | { |
| | 191 | 5 | | public string Id { get; init; } |
| | | 6 | | |
| | 160 | 7 | | protected Entity(string id) => Id = id; |
| | | 8 | | |
| | | 9 | | // Requerido para EF Core |
| | 15 | 10 | | protected Entity() { } |
| | | 11 | | |
| | | 12 | | public override bool Equals(object? obj) |
| | 4 | 13 | | { |
| | 4 | 14 | | if (obj is Entity other) |
| | 2 | 15 | | { |
| | 2 | 16 | | return Equals(other); |
| | | 17 | | } |
| | | 18 | | |
| | 2 | 19 | | return false; |
| | 4 | 20 | | } |
| | | 21 | | |
| | | 22 | | public bool Equals(Entity? other) |
| | 10 | 23 | | { |
| | 11 | 24 | | if (other is null) return false; |
| | 11 | 25 | | if (other.GetType() != GetType()) return false; |
| | 11 | 26 | | if (ReferenceEquals(this, other)) return true; |
| | 3 | 27 | | return Equals(Id, other.Id); |
| | 10 | 28 | | } |
| | | 29 | | |
| | 2 | 30 | | public override int GetHashCode() => Id.GetHashCode() * 41; |
| | | 31 | | |
| | | 32 | | public static bool operator ==(Entity? first, Entity? second) => |
| | 4 | 33 | | first is not null && first.Equals(second); |
| | | 34 | | |
| | | 35 | | public static bool operator !=(Entity? first, Entity? second) => |
| | 2 | 36 | | !(first == second); |
| | | 37 | | } |