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

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 emits a registration for every value object when this package is referenced, and — a hand-written type the System.Text.Json generator can see — hands the right converter back at run time. The lookup is a dictionary hit, so nothing here needs reflection or dynamic code.

Properties​

Count​

Gets the number of registered converters.

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.