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

Class NullableValueObjectComparer<TSelf>

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

Compares optional value objects using their own equality rather than the underlying value's, as compares required ones.

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

Type Parameters​

TSelf

Value object type.

Inheritance​

object ← ValueComparer ← ValueComparer<TSelf?> ← NullableValueObjectComparer<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​

The conventions give it to every property holding a TSelf?. Left to itself, Entity Framework Core would wrap for such a property, and the compiled model that dotnet ef dbcontext optimize writes for that wrapping does not compile: it names the comparer where the wrapper takes the value type. A comparer of the nullable type itself is written as it stands.

Two absent values are equal, an absent value equals no present one, and two present ones are equal when the value object says they are. A value object is immutable, so the snapshot is the value itself.

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​

NullableValueObjectComparer()​

Initializes a new instance of the class.

public NullableValueObjectComparer()