IDeserializationCallback vs OnDeserializedAttribute

前端 未结 4 2333
小蘑菇
小蘑菇 2021-02-19 10:45

As far as I understand, the IDeserializationCallback interface and the OnDeserialized event can both be used when an object needs to perform some task after being deserialized.<

4条回答
  •  一个人的身影
    2021-02-19 11:23

    Darren Headrick's post from above link (for completeness) :

    DeserializationCallback.OnDeserialization "Runs when the entire object graph has been deserialized." (link).

    The OnDeserialized event however "Use the OnDeserializedAttribute when you need to fix values on a deserialized object after it has been deserialized and before the graph is returned. This attribute can be used instead of the IDeserializationCallback interface." (link).

    Since the OnDeserialized attribute can be used to modify the object graph, it gets called before OnDeserialization (which signifies the Object graph is in its final state).

提交回复
热议问题