Class ValueObjectConverter<TSelf, TValue>
Namespace: AdCodicem.ValueObjects.EntityFrameworkCore
Assembly: AdCodicem.ValueObjects.EntityFrameworkCore.dll
Stores a value object as its bare underlying value.
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "A compiled model calls the conversions on the converter type it was built from.")]
public sealed class ValueObjectConverter<TSelf, TValue> : ValueConverter<TSelf, TValue> where TSelf : struct, IValueObject<TSelf, TValue>
Type Parameters
TSelf
Value object type.
TValue
Underlying value type.
Inheritance
object ← ValueConverter ← ValueConverter<TSelf, TValue> ← ValueObjectConverter<TSelf, TValue>
Inherited Members
ValueConverter<TSelf, TValue>.ConvertToProvider, ValueConverter<TSelf, TValue>.ConvertFromProvider, ValueConverter<TSelf, TValue>.ConvertToProviderTyped, ValueConverter<TSelf, TValue>.ConvertFromProviderTyped, ValueConverter<TSelf, TValue>.ConvertToProviderExpression, ValueConverter<TSelf, TValue>.ConvertFromProviderExpression, ValueConverter<TSelf, TValue>.ModelClrType, ValueConverter<TSelf, TValue>.ProviderClrType, ValueConverter<TSelf, TValue>.ConstructorExpression, ValueConverter.ComposeWith(ValueConverter?), ValueConverter.ConvertToProvider, ValueConverter.ConvertFromProvider, ValueConverter.ConvertToProviderExpression, ValueConverter.ConvertFromProviderExpression, ValueConverter.ModelClrType, ValueConverter.ProviderClrType, ValueConverter.MappingHints, ValueConverter.ConvertsNulls, ValueConverter.ConstructorExpression, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
Reading uses the trusted factory: no normalization, no validation, no allocation beyond the value itself.
Materializing an entity is the hottest path in most applications, and the rows being read were written by
this same application through the validating factory. Use
Writing refuses a value the value object rejects, with a default(TSelf) can hold one, since any other
went through Create, so only that one is validated: over a value type, a constructed zero equals the default
too, and validation tells a valid zero, which is stored, from a refused one. A property holding a TSelf? is
mapped through NULL.
Both directions go through static helpers rather than inline lambdas, because an expression tree cannot
contain a call to a static abstract interface member. The helpers are public, out of sight of IntelliSense: the
code of a compiled model, which dotnet ef dbcontext optimize writes into the application's assembly, calls
them there, as it calls whatever a converter calls when it is generated for native AOT.
Constructors
ValueObjectConverter()
Initializes a new instance of the
public ValueObjectConverter()