Json.net ContractResolver

时间:2018-09-04 14:55:58

标签: c# json.net

如何确定是从Serializiaton调用还是反序列化?

我需要这样的东西:

protected override IValueProvider CreateMemberValueProvider(MemberInfo member)
{
    IValueProvider valueProvider = base.CreateMemberValueProvider(member);

    if (member.CustomAttributes.First().AttributeType == typeof(EncryptedAttribute))
    {
        object value = valueProvider.GetValue(_object);
        if(IsInSerialization())
        {
            valueProvider.SetValue(_object, Encrypt(value));
        }
        else
        {
            valueProvider.SetValue(_object, Decrypt(value));
        }
    }
    return valueProvider;
}

0 个答案:

没有答案