22
33namespace Winton . DomainModelling
44{
5+ /// <inheritdoc />
6+ /// <summary>
7+ /// A base class to implement entity types, which are defined by their identity rather than their attributes.
8+ /// </summary>
9+ /// <typeparam name="TEntityId">The ID type for the entity type.</typeparam>
510 public abstract class Entity < TEntityId > : IEquatable < Entity < TEntityId > >
611 where TEntityId : IEquatable < TEntityId >
712 {
13+ /// <summary>
14+ /// Initializes a new instance of the <see cref="Entity{TEntityId}" /> class.
15+ /// </summary>
16+ /// <param name="id">The ID for the entity.</param>
817 protected Entity ( TEntityId id )
918 {
1019 Id = id ;
1120 }
1221
22+ /// <summary>
23+ /// Gets the ID for the entity.
24+ /// </summary>
1325 public TEntityId Id { get ; }
1426
27+ /// <summary>
28+ /// Indicates whether two entities are equal.
29+ /// </summary>
30+ /// <param name="left">The first entity.</param>
31+ /// <param name="right">The second entity.</param>
32+ /// <returns><see langword="true" /> if the entities have the same ID; otherwise, <see langword="false" />.</returns>
1533 public static bool operator == ( Entity < TEntityId > left , Entity < TEntityId > right )
1634 {
1735 return Equals ( left , right ) ;
1836 }
1937
38+ /// <summary>
39+ /// Indicates whether two entities are unequal.
40+ /// </summary>
41+ /// <param name="left">The first entity.</param>
42+ /// <param name="right">The second entity.</param>
43+ /// <returns><see langword="true" /> if the entities have different IDs; otherwise, <see langword="false" />.</returns>
2044 public static bool operator != ( Entity < TEntityId > left , Entity < TEntityId > right )
2145 {
2246 return ! Equals ( left , right ) ;
2347 }
2448
49+ /// <inheritdoc />
50+ /// <summary>
51+ /// Indicates whether the current entity is equal to another entity.
52+ /// </summary>
53+ /// <param name="other">An entity to compare with this entity.</param>
54+ /// <returns>
55+ /// <see langword="true" /> if the current entity has the same ID as the <paramref name="other" /> entity;
56+ /// otherwise, <see langword="false" />.
57+ /// </returns>
2558 public bool Equals ( Entity < TEntityId > other )
2659 {
2760 if ( other is null )
@@ -42,11 +75,23 @@ public bool Equals(Entity<TEntityId> other)
4275 return ! Id . Equals ( default ( TEntityId ) ) && ! other . Id . Equals ( default ( TEntityId ) ) && Id . Equals ( other . Id ) ;
4376 }
4477
78+ /// <summary>
79+ /// Determines whether the specified object is equal to the current object.
80+ /// </summary>
81+ /// <param name="obj">The object to compare with the current object.</param>
82+ /// <returns>
83+ /// <see langword="true" /> if the specified object is equal to the current object; otherwise,
84+ /// <see langword="false" />.
85+ /// </returns>
4586 public override bool Equals ( object obj )
4687 {
4788 return Equals ( obj as Entity < TEntityId > ) ;
4889 }
4990
91+ /// <summary>
92+ /// Serves as the default hash function.
93+ /// </summary>
94+ /// <returns>A hash code for the current object.</returns>
5095 public override int GetHashCode ( )
5196 {
5297 return Id . GetHashCode ( ) ;
0 commit comments