I wrote a custom JsonConverter called CompententsConverter
and it works fine, however I'm curious if there is a way to make use of the alternate constructor which takes params object[] converterParameters and pass over my own custom parameters from the attribute accordingly.
Likewise, I am not sure how to actually retrieve the parameters inside the JsonConverter class definition or if it's even possible to do this with a JsonConverter attribute.
inside the model, attribute with theoretical params, where some_parameter_here
is a placeholder for a constant expression:
[JsonProperty("components")]
[JsonConverter(typeof(ComponentsConverter), some_parameter_here)]
public List<ComponentModel> Components { get; set; }
ComponentsConverter custom JsonConverter:
public class ComponentsConverter : JsonConverter
{
public override bool CanConvert (Type t) => t == typeof(List<ComponentModel>);
public override object ReadJson (JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
// ... any way to access params object[] customParameters here?
}
public override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer)
{
// ...
}
}
Would be nice to be able to define some custom conversion behavior for specific model properties by using these extra params.