Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectComparer<TSelf>

Namespace: AdCodicem.ValueObjects.EntityFrameworkCore
Assembly: AdCodicem.ValueObjects.EntityFrameworkCore.dll

Compares value objects using their own equality rather than the underlying value's.

public sealed class ValueObjectComparer<TSelf> : ValueComparer<TSelf>, IEqualityComparer, IEqualityComparer<object>, IEqualityComparer<TSelf> where TSelf : struct, IEquatable<TSelf>

Type Parameters​

TSelf

Value object type.

Inheritance​

object ← ValueComparer ← ValueComparer<TSelf> ← ValueObjectComparer<TSelf>

Implements​

IEqualityComparer, IEqualityComparer<object>, IEqualityComparer<TSelf>

Inherited Members​

ValueComparer<TSelf>.Equals(object?, object?), ValueComparer<TSelf>.GetHashCode(object?), ValueComparer<TSelf>.Equals(TSelf, TSelf), ValueComparer<TSelf>.GetHashCode(TSelf), ValueComparer<TSelf>.Snapshot(object?), ValueComparer<TSelf>.Snapshot(TSelf), ValueComparer<TSelf>.ObjectEqualsExpression, ValueComparer<TSelf>.Type, ValueComparer<TSelf>.EqualsExpression, ValueComparer<TSelf>.HashCodeExpression, ValueComparer<TSelf>.SnapshotExpression, ValueComparer.GetGenericSnapshotMethod(Type), ValueComparer.Equals(object?, object?), ValueComparer.GetHashCode(object?), ValueComparer.Snapshot(object?), ValueComparer.ExtractEqualsBody(Expression, Expression), ValueComparer.ExtractHashCodeBody(Expression), ValueComparer.ExtractSnapshotBody(Expression), ValueComparer.Add(HashCode, int), ValueComparer.CreateDefault(Type, bool), ValueComparer.CreateDefault<T>(bool), ValueComparer.Type, ValueComparer.EqualsExpression, ValueComparer.ObjectEqualsExpression, ValueComparer.HashCodeExpression, ValueComparer.SnapshotExpression, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

This matters as soon as a value object declares a comparison other than ordinal: without it, change tracking would consider ORD-42 and ord-42 different for a case-insensitive reference and issue an UPDATE that changes nothing. A value object is immutable, so the snapshot is the value itself.

A property holding a TSelf? takes , which a compiled model can write, where it cannot write the wrapping Entity Framework Core would give this comparer.

TSelf carries the annotation puts on its own type argument, so that an application trimmed or published with native AOT gets no warning for the comparer its model names.

Constructors​

ValueObjectComparer()​

Initializes a new instance of the class.

public ValueObjectComparer()