namespace Knot.Shared.Kernel;
///
/// Базовый класс для всех сущностей в системе.
///
/// Тип идентификатора сущности.
public abstract class Entity : IEquatable>
where TId : notnull
{
public TId Id { get; protected set; }
protected Entity(TId id)
{
Id = id;
}
public override bool Equals(object? obj)
{
return obj is Entity entity && Equals(entity);
}
public bool Equals(Entity? other)
{
if (other is null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Id.Equals(other.Id);
}
public static bool operator ==(Entity? left, Entity? right)
{
return Equals(left, right);
}
public static bool operator !=(Entity? left, Entity? right)
{
return !Equals(left, right);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
}