I want to pass value of property Field1
as parameter to Newtonsoft.Json.JsonConverter
that’s applied on Data
property. I tried [JsonConverter(typeof(HardwareParamJsonConverter), Field1)]
, but obviously get CS0120: An object reference is required for the nonstatic field, method, or property 'Message.Field1'
error when I try to deserialize JsonConvert.DeserializeObject<Message>(msgJson);
. What can I do to achieve this?
public class Message
{
[JsonProperty(Required = Required.Always)]
public int Field1 { get; set; }
[JsonProperty(Required = Required.Always)]
public string Field2 { get; set; }
[JsonConverter(typeof(MyClassJsonConverter))]
[JsonProperty(Required = Required.Always)]
public MyClass Data { get; set; }
}