Struct EqualityComponents
- Namespace
- Trellis
- Assembly
- Trellis.Core.dll
Collects the components that define a ValueObject's structural equality.
public ref struct EqualityComponents
- Inherited Members
Examples
protected override void GetEqualityComponents(ref EqualityComponents components)
{
components.Add(Street);
components.Add(City);
components.Add(PostalCode);
}
Remarks
A ref struct sink passed by reference to
GetEqualityComponents(ref EqualityComponents). Components are written
into a caller-owned inline buffer, so equality, ordering, and hashing traverse a value object's
components without allocating. The previous IEnumerable<IComparable?> contract
allocated an iterator state machine on every comparison.
Add components in a stable, deterministic order. Derived types that extend a base value object
should call base.GetEqualityComponents(ref components) first so the base components keep
their positions.
Properties
Count
The number of components added so far.
public readonly int Count { get; }
Property Value
Methods
Add(IComparable?)
Adds a component to the equality definition. null is a valid component and sorts before every non-null component.
public void Add(IComparable? component)
Parameters
componentIComparableThe component value.
Add<T>(Maybe<T>)
Adds an optional component, treating None as a null component so present and absent values order consistently.
public void Add<T>(Maybe<T> maybe) where T : notnull, IComparable
Parameters
maybeMaybe<T>The optional value.
Type Parameters
TThe optional value's type.