问题
I am using Json.NET to serialize an object graph. For each object that is serialized or deserialized, I want to call a method on that object before the serialization takes place. For e.g. all my objects implement an interface INotified with a method OnSerializing. I want OnSerializing to be called before the object is serialized.
Is there a way to achieve this without having to touch the Json.NET source code?
回答1:
The latest version of Json.NET supports serialization callbacks.
来源:https://stackoverflow.com/questions/1048311/json-net-serialization-pre-and-post-calls