Jarstat

Форк
0
56 строк · 1.4 Кб
1
using Jarstat.Domain.Entities;
2

3
namespace Jarstat.Domain.Primitives;
4

5
public 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 Core
8
    //protected Entity(Guid id) => Id = id;
9
    //protected Entity() { }
10

11
    public Guid Id { get; protected init; }
12
    public DateTime DateTimeCreated { get; protected init; }
13
    public DateTime DateTimeUpdated { get; protected set; }
14
    public User Creator { get; protected init; } = null!;
15
    public User LastUpdater { get; protected set; } = null!;
16

17
    public static bool operator ==(Entity? first, Entity? second)
18
    {
19
        return first is not null && second is not null && first.Equals(second);
20
    }
21

22
    public static bool operator !=(Entity? first, Entity? second)
23
    {
24
        return !(first == second);
25
    }
26

27
    public bool Equals(Entity? other)
28
    {
29
        if (other is null)
30
            return false;
31

32
        if (other.GetType() != GetType())
33
            return false;
34

35
        return other.Id == Id;
36
    }
37

38
    public override bool Equals(object? obj)
39
    {
40
        if (obj is null)
41
            return false;
42

43
        if (obj.GetType() != GetType())
44
            return false;
45

46
        if (obj is not Entity entity)
47
            return false;
48

49
        return entity.Id == Id;
50
    }
51

52
    public override int GetHashCode()
53
    {
54
        return Id.GetHashCode() * 79;
55
    }
56
}
57

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.