Skip to content

Commit a174b38

Browse files
author
Iain Scott
committed
Documented Entity.
1 parent 803f7ce commit a174b38

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/Winton.DomainModelling.Abstractions/Entity.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,59 @@
22

33
namespace 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();

src/Winton.DomainModelling.Abstractions/Winton.DomainModelling.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Company>Winton</Company>
66
<Copyright>Copyright 2018 Winton</Copyright>
77
<Description>Provides common abstractions for domain modelling.</Description>
8-
<GenerateDocumentationFile>False</GenerateDocumentationFile>
8+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
99
<NoWarn>$(NoWarn);SA0001;SA1101;SA1309;SA1413;SA1633;SA1652</NoWarn>
1010
<PackageId>Winton.DomainModelling.Abstractions</PackageId>
1111
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>

0 commit comments

Comments
 (0)