main
1using System;
2using gorilla.utility;
3
4namespace solidware.financials.service.domain
5{
6 public class Entity : IEquatable<Entity>, Identifiable<Guid>
7 {
8 protected Entity()
9 {
10 id = Id<Guid>.Default;
11 }
12
13 public virtual Id<Guid> id { get; set; }
14
15 public virtual bool Equals(Entity other)
16 {
17 if (ReferenceEquals(null, other)) return false;
18 if (ReferenceEquals(this, other)) return true;
19 if (id.Equals(Id<Guid>.Default) || other.id.Equals(Id<Guid>.Default)) return false;
20 return other.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 is Entity)) return false;
28 return Equals((Entity) obj);
29 }
30
31 public override int GetHashCode()
32 {
33 return id.GetHashCode();
34 }
35
36 static public bool operator ==(Entity left, Entity right)
37 {
38 return Equals(left, right);
39 }
40
41 static public bool operator !=(Entity left, Entity right)
42 {
43 return !Equals(left, right);
44 }
45 }
46}