main
 1using System;
 2using gorilla.commons.utility;
 3
 4namespace MoMoney.Domain.Core
 5{
 6    [Serializable]
 7    public abstract class GenericEntity<T> : Entity where T : class, Entity
 8    {
 9        protected GenericEntity()
10        {
11            id = Guid.NewGuid();
12        }
13
14        public Id<Guid> id { get; private set; }
15
16        public bool Equals(GenericEntity<T> obj)
17        {
18            if (ReferenceEquals(null, obj)) return false;
19            if (ReferenceEquals(this, obj)) return true;
20            return obj.id.Equals(id);
21        }
22
23        public override bool Equals(object obj)
24        {
25            if (ReferenceEquals(null, obj)) return false;
26            if (ReferenceEquals(this, obj)) return true;
27            if (obj.GetType() != typeof (GenericEntity<T>)) return false;
28            return Equals((GenericEntity<T>) obj);
29        }
30
31        public override int GetHashCode()
32        {
33            return id.GetHashCode();
34        }
35
36        public override string ToString()
37        {
38            return "{0} id: {1}".formatted_using(base.ToString(), id);
39        }
40    }
41}