Skip to main content
Version: 0.2.x (0.2.1)

Class ValueObjectRegistry

Namespace: AdCodicem.ValueObjects.Metadata
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Process-wide directory of the value object types known to the application.

public static class ValueObjectRegistry

Inheritance​

object ← ValueObjectRegistry

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

The source generator emits a module initializer per assembly that registers every generated value object, so the common case is a lock-free dictionary hit with no reflection and no dynamic code — the registry is therefore usable under native AOT.

additionally falls back to reflection for hand-written value objects and for modules whose initializer has not run yet. It is annotated as requiring dynamic code, and its result is cached, so a given type pays that cost at most once.

Methods​

EnsureAssemblyRegistered(Assembly)​

Runs the generated registration of an assembly, if it has one.

[RequiresUnreferencedCode("Locating the generated registration type of an assembly requires its metadata.")]
public static void EnsureAssemblyRegistered(Assembly assembly)

Parameters​

assembly Assembly

Assembly declaring value objects.

Remarks​

Module initializers are triggered by the first access to a member of the module, which model-building code that only reflects over types may never perform. Integrations call this before enumerating types.

GetRegistered()​

Gets the descriptors registered so far.

public static IReadOnlyCollection<ValueObjectDescriptor> GetRegistered()

Returns​

IReadOnlyCollection<ValueObjectDescriptor>

A snapshot of the registered descriptors.

GetUnderlyingType(Type)​

Gets the underlying value type of a value object.

[UnconditionalSuppressMessage("Trimming", "IL2070:UnrecognizedReflectionPattern", Justification = "The interface list of a value object is preserved: the type is referenced by the caller and its IValueObject implementation is part of its public contract.")]
public static Type? GetUnderlyingType(Type type)

Parameters​

type Type

Value object type, possibly nullable.

Returns​

Type?

The underlying value type, or null when the type is not a value object.

IsValueObject(Type)​

Determines whether a type is a value object.

public static bool IsValueObject(Type type)

Parameters​

type Type

Type to test, possibly nullable.

Returns​

bool

true when the type implements .

Register(ValueObjectDescriptor)​

Registers a descriptor, replacing any previous registration for the same type.

public static void Register(ValueObjectDescriptor descriptor)

Parameters​

descriptor ValueObjectDescriptor

Descriptor to register.

Register<TSelf, TValue>(ValueObjectSchema)​

Registers a value object without reflection.

public static void Register<TSelf, TValue>(ValueObjectSchema schema) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

schema ValueObjectSchema

Declarative constraints of the value object.

Type Parameters​

TSelf

Value object type.

TValue

Underlying value type.

TryGet(Type, out ValueObjectDescriptor?)​

Looks up an already registered descriptor.

public static bool TryGet(Type type, out ValueObjectDescriptor? descriptor)

Parameters​

type Type

Value object type, possibly nullable.

descriptor ValueObjectDescriptor?

The descriptor when found.

Returns​

bool

true when a descriptor is registered for type.

TryResolve(Type, out ValueObjectDescriptor?)​

Looks up a descriptor, building it by reflection when the type has not registered itself.

[RequiresDynamicCode("Building a descriptor for an unregistered value object instantiates a generic method at run time.")]
[RequiresUnreferencedCode("Building a descriptor for an unregistered value object inspects its interfaces and attributes.")]
public static bool TryResolve(Type type, out ValueObjectDescriptor? descriptor)

Parameters​

type Type

Value object type, possibly nullable.

descriptor ValueObjectDescriptor?

The descriptor when the type is a value object.

Returns​

bool

true when type is a value object.