Skip to main content
Version: Preview (0.3.0-preview.205)

Class ValueObjectJsonRegistry

Namespace: AdCodicem.ValueObjects.Json
Assembly: AdCodicem.ValueObjects.Json.dll

Directory of the converters generated for the value objects of the loaded assemblies.

public static class ValueObjectJsonRegistry

Inheritance​

object ← ValueObjectJsonRegistry

Inherited Members​

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

Remarks​

A source generator only ever sees the original compilation, never the output of another generator. The [JsonConverter] attribute placed on a generated value object is therefore invisible to the System.Text.Json generator, and a JsonSerializerContext would otherwise fall back to serializing the value object as an object with properties.

This registry closes that gap. The value object generator registers the converter of every value object with its descriptor in , whatever the declaring assembly references, and — a hand-written type the System.Text.Json generator can see — hands the right converter back at run time. A converter registered here, for a value object written by hand, comes first. The lookup is a dictionary hit, so nothing here needs reflection or dynamic code.

Properties​

Count​

Gets the number of converters registered here, those registered with a descriptor aside.

public static int Count { get; }

Property Value​

int

Methods​

Register<TSelf>(JsonConverter<TSelf>)​

Registers the converter of a value object.

public static void Register<TSelf>(JsonConverter<TSelf> converter) where TSelf : struct

Parameters​

converter JsonConverter<TSelf>

Converter to register.

Type Parameters​

TSelf

Value object type.

TryGet(Type, out JsonConverter?)​

Looks up the converter registered for a value object type.

public static bool TryGet(Type type, out JsonConverter? converter)

Parameters​

type Type

Value object type.

converter JsonConverter?

The registered converter.

Returns​

bool

true when a converter is registered here, or with the descriptor of the type, as the generator registers it.

Remarks​

over a value object has no converter of its own: the serializer wraps the converter of the value object itself.