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, bool>, 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
predicateFunc<Type, bool>The function delegate that validates if a given Type can be converted to and from JSON.
converterFactoryFunc<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
typeToConvertTypeThe type of the object to convert.
converterFactoryFunc<Type, JsonSerializerOptions, JsonConverter>The function delegate that converts
typeToConvertto 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(ref Utf8JsonReader, Type, JsonSerializerOptions) through reader.
public static JsonConverter Create<T>(Utf8JsonWriterAction<T> writer = null, Utf8JsonReaderFunc<T> reader = null)
Parameters
writerUtf8JsonWriterAction<T>The delegate that converts
Tto its JSON representation.readerUtf8JsonReaderFunc<T>The function delegate that generates
Tfrom its JSON representation.
Returns
- JsonConverter
An JsonConverter implementation of
T.
Type Parameters
TThe type to implement an JsonConverter.
Create<T>(Func<Type, bool>, Utf8JsonWriterAction<T>, Utf8JsonReaderFunc<T>)
Creates a dynamic instance of an JsonConverter implementation wrapping Write(Utf8JsonWriter, T, JsonSerializerOptions) through writer and Read(ref Utf8JsonReader, Type, JsonSerializerOptions) through reader.
public static JsonConverter Create<T>(Func<Type, bool> predicate, Utf8JsonWriterAction<T> writer = null, Utf8JsonReaderFunc<T> reader = null)
Parameters
predicateFunc<Type, bool>The function delegate that validates if given Type can be converted to and from JSON.
writerUtf8JsonWriterAction<T>The delegate that, when
predicatereturns true, convertsTto its JSON representation.readerUtf8JsonReaderFunc<T>The function delegate that, when
predicatereturns true, generatesTfrom its JSON representation.
Returns
- JsonConverter
An JsonConverter implementation of
T.
Type Parameters
TThe type to implement an JsonConverter.