是OnDeserializedAttribute支持每串行? [英] Is OnDeserializedAttribute Supported by Every Serializer?

查看:161
本文介绍了是OnDeserializedAttribute支持每串行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对面<一个偶然href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.ondeserializedattribute.aspx"相对=nofollow> OnDeserializedAttribute MSDN上。该说明指出

  

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

问题

  1. 在与该属性的方法要求的任意的序列化?
  2. 如果是这样,如何​​.NET保证该方法被调用任意串行?
  3. 如果不是,它支持所有的共同串行(BinaryFormatter的,XmlSerializer的,JSON序列,DataContractSerializer的)?
解决方案
  1. 没有。 <一href="http://stackoverflow.com/questions/2897166/why-does-the-ondeserialization-not-fire-for-xml-deserialization">It上不XmlSerializer的的工作。
  2. 在它没有做任何执行。这是一个串行的选入功能。
  3. 在它上的BinaryFormatter和DataContractSerializer的工作。

I just stumbled across OnDeserializedAttribute on MSDN. The description states

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

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

解决方案

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

这篇关于是OnDeserializedAttribute支持每串行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆