2

我有一套西装。我想对某些属性进行自定义反序列化。但我想在单个转换器类中处理它。不想为每个班级单独写。那么有没有办法找到调用 ReadJson 的属性名称?

// My Class
public class SomeClass
{
    // Private members
    private double m_nValue;
    private string m_strValue;

    // Properties
    [JsonConverter(typeof(AlfhaConverter))]
    public double Value
    {
        get { return m_nValue; }
        set { m_nValue = value; }
    }

    [JsonConverter(typeof(AlfhaConverter))]
    public string StrValue
    {
        get { return m_strValue; }
        set { m_strValue = value; }
    }
}

// JsonConverter
public class PropertyConverter : JsonConverter
{
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        //Here i want to find the property name so that i can perform certain steps based on the property
    }

    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        serializer.Serialize(writer, value);
    }
}
4

0 回答 0