Class JsonConverterFactory
- Namespace
- Codebelt.Extensions.Newtonsoft.Json
- Assembly
- Codebelt.Extensions.Newtonsoft.Json.dll
Provides a factory based way to create and wrap an Newtonsoft.Json.JsonConverter implementation.
public static class JsonConverterFactory
- Inheritance
-
JsonConverterFactory
Methods
Create(JsonConverter)
Creates a dynamic instance of converter
.
public static JsonConverter Create(JsonConverter converter)
Parameters
converter
JsonConverterThe Newtonsoft.Json.JsonConverter to wrap.
Returns
- JsonConverter
An Newtonsoft.Json.JsonConverter implementation of Type.
Create(Func<Type, Boolean>, Action<JsonWriter, Object, JsonSerializer>, Func<JsonReader, Type, Object, JsonSerializer, Object>)
Creates a dynamic instance of an Newtonsoft.Json.JsonConverter implementation wrapping Newtonsoft.Json.JsonConverter.CanConvert(System.Type) through predicate
, Newtonsoft.Json.JsonConverter.WriteJson(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.JsonSerializer) through writer
and Newtonsoft.Json.JsonConverter.ReadJson(Newtonsoft.Json.JsonReader, System.Type, System.Object, Newtonsoft.Json.JsonSerializer) through reader
.
public static JsonConverter Create(Func<Type, bool> predicate, Action<JsonWriter, object, JsonSerializer> writer = null, Func<JsonReader, Type, object, JsonSerializer, object> reader = null)
Parameters
predicate
Func<Type, Boolean>The function delegate that validates if given Type can be converted to and from JSON.
writer
Action<JsonWriter, Object, JsonSerializer>The delegate that converts a given Type to its JSON representation.
reader
Func<JsonReader, Type, Object, JsonSerializer, Object>The function delegate that generates Type from its JSON representation.
Returns
- JsonConverter
An Newtonsoft.Json.JsonConverter implementation of Type.
Create(Type, Action<JsonWriter, Object, JsonSerializer>, Func<JsonReader, Type, Object, JsonSerializer, Object>)
Creates a dynamic instance of an Newtonsoft.Json.JsonConverter implementation wrapping Newtonsoft.Json.JsonConverter.WriteJson(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.JsonSerializer) through writer
and Newtonsoft.Json.JsonConverter.ReadJson(Newtonsoft.Json.JsonReader, System.Type, System.Object, Newtonsoft.Json.JsonSerializer) through reader
.
public static JsonConverter Create(Type objectType, Action<JsonWriter, object, JsonSerializer> writer = null, Func<JsonReader, Type, object, JsonSerializer, object> reader = null)
Parameters
objectType
TypeThe type of the object to convert.
writer
Action<JsonWriter, Object, JsonSerializer>The delegate that converts
objectType
to its JSON representation.reader
Func<JsonReader, Type, Object, JsonSerializer, Object>The function delegate that generates
objectType
from its JSON representation.
Returns
- JsonConverter
An Newtonsoft.Json.JsonConverter implementation of
objectType
.
Create<T>(Action<JsonWriter, T, JsonSerializer>, Func<JsonReader, Type, T, JsonSerializer, T>)
Creates a dynamic instance of an Newtonsoft.Json.JsonConverter implementation wrapping Newtonsoft.Json.JsonConverter.WriteJson(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.JsonSerializer) through writer
and Newtonsoft.Json.JsonConverter.ReadJson(Newtonsoft.Json.JsonReader, System.Type, System.Object, Newtonsoft.Json.JsonSerializer) through reader
.
public static JsonConverter Create<T>(Action<JsonWriter, T, JsonSerializer> writer = null, Func<JsonReader, Type, T, JsonSerializer, T> reader = null)
Parameters
writer
Action<JsonWriter, T, JsonSerializer>The delegate that converts
T
to its JSON representation.reader
Func<JsonReader, Type, T, JsonSerializer, T>The function delegate that generates
T
from its JSON representation.
Returns
- JsonConverter
An Newtonsoft.Json.JsonConverter implementation of
T
.
Type Parameters
T
The type to implement an Newtonsoft.Json.JsonConverter.
Create<T>(Func<Type, Boolean>, Action<JsonWriter, T, JsonSerializer>, Func<JsonReader, Type, T, JsonSerializer, T>)
Creates a dynamic instance of an Newtonsoft.Json.JsonConverter implementation wrapping Newtonsoft.Json.JsonConverter.WriteJson(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.JsonSerializer) through writer
and Newtonsoft.Json.JsonConverter.ReadJson(Newtonsoft.Json.JsonReader, System.Type, System.Object, Newtonsoft.Json.JsonSerializer) through reader
.
public static JsonConverter Create<T>(Func<Type, bool> predicate, Action<JsonWriter, T, JsonSerializer> writer = null, Func<JsonReader, Type, T, JsonSerializer, T> reader = null)
Parameters
predicate
Func<Type, Boolean>The function delegate that validates if given Type can be converted to and from JSON.
writer
Action<JsonWriter, T, JsonSerializer>The delegate that, when
predicate
returns true, convertsT
to its JSON representation.reader
Func<JsonReader, Type, T, JsonSerializer, T>The function delegate that, when
predicate
returns true, generatesT
from its JSON representation.
Returns
- JsonConverter
An Newtonsoft.Json.JsonConverter implementation of
T
.
Type Parameters
T
The type to implement an Newtonsoft.Json.JsonConverter.