Table of Contents

Class DynamicJsonConverter

Namespace
Cuemon.Extensions.Text.Json
Assembly
Cuemon.Extensions.Text.Json.dll

Provides a factory based way to create and wrap an JsonConverter implementation.

public static class DynamicJsonConverter
Inheritance
DynamicJsonConverter

Methods

Create(Func<Type, Boolean>, Func<Type, JsonSerializerOptions, JsonConverter>)

Creates a dynamic instance of an JsonConverter implementation wrapping CanConvert(Type) through predicate and CreateConverter(Type, JsonSerializerOptions) through converterFactory.

public static JsonConverter Create(Func<Type, bool> predicate, Func<Type, JsonSerializerOptions, JsonConverter> converterFactory)

Parameters

predicate Func<Type, Boolean>

The function delegate that validates if a given Type can be converted to and from JSON.

converterFactory Func<Type, JsonSerializerOptions, JsonConverter>

The function delegate that converts a given Type to its JSON representation using a factory pattern.

Returns

JsonConverter

An JsonConverter implementation of Type.

Create(Type, Func<Type, JsonSerializerOptions, JsonConverter>)

Creates a dynamic instance of an JsonConverter implementation wrapping CanConvert(Type) through typeToConvert and CreateConverter(Type, JsonSerializerOptions) through converterFactory.

public static JsonConverter Create(Type typeToConvert, Func<Type, JsonSerializerOptions, JsonConverter> converterFactory)

Parameters

typeToConvert Type

The type of the object to convert.

converterFactory Func<Type, JsonSerializerOptions, JsonConverter>

The function delegate that converts typeToConvert to its JSON representation using a factory pattern.

Returns

JsonConverter

An JsonConverter implementation of typeToConvert.

Create<T>(Utf8JsonWriterAction<T>, Utf8JsonReaderFunc<T>)

Creates a dynamic instance of an JsonConverter implementation wrapping Write(Utf8JsonWriter, T, JsonSerializerOptions) through writer and Read(Utf8JsonReader, Type, JsonSerializerOptions) through reader.

public static JsonConverter Create<T>(Utf8JsonWriterAction<T> writer = null, Utf8JsonReaderFunc<T> reader = null)

Parameters

writer Utf8JsonWriterAction<T>

The delegate that converts T to its JSON representation.

reader Utf8JsonReaderFunc<T>

The function delegate that generates T from its JSON representation.

Returns

JsonConverter

An JsonConverter implementation of T.

Type Parameters

T

The type to implement an JsonConverter.

Create<T>(Func<Type, Boolean>, Utf8JsonWriterAction<T>, Utf8JsonReaderFunc<T>)

Creates a dynamic instance of an JsonConverter implementation wrapping Write(Utf8JsonWriter, T, JsonSerializerOptions) through writer and Read(Utf8JsonReader, Type, JsonSerializerOptions) through reader.

public static JsonConverter Create<T>(Func<Type, bool> predicate, Utf8JsonWriterAction<T> writer = null, Utf8JsonReaderFunc<T> reader = null)

Parameters

predicate Func<Type, Boolean>

The function delegate that validates if given Type can be converted to and from JSON.

writer Utf8JsonWriterAction<T>

The delegate that, when predicate returns true, converts T to its JSON representation.

reader Utf8JsonReaderFunc<T>

The function delegate that, when predicate returns true, generates T from its JSON representation.

Returns

JsonConverter

An JsonConverter implementation of T.

Type Parameters

T

The type to implement an JsonConverter.