Value Objects
/// <summary>
/// Value object
/// </summary>
/// <typeparam name="T">The type of value object class</typeparam>
public abstract class ValueObject<T> where T : ValueObject<T>
{
/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
T other = (T)obj;
return GetEqualityComponents().SequenceEqual(other.GetEqualityComponents());
}
/// <inheritdoc/>
public override int GetHashCode()
{
return GetEqualityComponents()
.Aggregate(17, (current, obj) => current * 23 + (obj?.GetHashCode() ?? 0));
}
/// <inheritdoc/>
protected abstract IEnumerable<object> GetEqualityComponents();
}Last updated