Jarstat
56 строк · 1.4 Кб
1using Jarstat.Domain.Entities;2
3namespace Jarstat.Domain.Primitives;4
5public abstract class Entity : IEquatable<Entity>6{
7// TODO: figure out how to use protected constructor of the base class instead of default constructors with EF Core8//protected Entity(Guid id) => Id = id;9//protected Entity() { }10
11public Guid Id { get; protected init; }12public DateTime DateTimeCreated { get; protected init; }13public DateTime DateTimeUpdated { get; protected set; }14public User Creator { get; protected init; } = null!;15public User LastUpdater { get; protected set; } = null!;16
17public static bool operator ==(Entity? first, Entity? second)18{19return first is not null && second is not null && first.Equals(second);20}21
22public static bool operator !=(Entity? first, Entity? second)23{24return !(first == second);25}26
27public bool Equals(Entity? other)28{29if (other is null)30return false;31
32if (other.GetType() != GetType())33return false;34
35return other.Id == Id;36}37
38public override bool Equals(object? obj)39{40if (obj is null)41return false;42
43if (obj.GetType() != GetType())44return false;45
46if (obj is not Entity entity)47return false;48
49return entity.Id == Id;50}51
52public override int GetHashCode()53{54return Id.GetHashCode() * 79;55}56}
57