是OnDeserializedAttribute支持每串行?串行、OnDeserializedAttribute

2023-09-05 04:17:07 作者:劇ぃ蔠ゞ

我对面 OnDeserializedAttribute MSDN上。该说明指出

  

当应用于方法,指定方法被称为一个对象的对象图中的反序列化后立即使用。相对于图中的其他对象反序列化的顺序是非确定性的。

问题

在与该属性的方法要求的任意的序列化? 如果是这样,如何​​.NET保证该方法被调用任意串行? 如果不是,它支持所有的共同串行(BinaryFormatter的,XmlSerializer的,JSON序列,DataContractSerializer的)? 解决方案 没有。 It上不XmlSerializer的的工作。 在它没有做任何执行。这是一个串行的选入功能。 在它上的BinaryFormatter和DataContractSerializer的工作。

I just stumbled across OnDeserializedAttribute on MSDN. The description states

JESD204B 01协议规范的详细资料说明

When applied to a method, specifies that the method is called immediately after deserialization of an object in an object graph. The order of deserialization relative to other objects in the graph is non-deterministic.

Questions

Is a method with this attribute called for any serializer? If so, how does .NET ensure the method is called for an arbitrary serializer? If not, is it supported for all of the "common" serializers (BinaryFormatter, XmlSerializer, JSON Serializer, DataContractSerializer)?

解决方案

No. It does not work on the XmlSerializer. It doesn't do any enforcement. It's an "opt-in" functionality for a serializer. It does work on BinaryFormatter and DataContractSerializer.