Why does the OnDeserialization not fire for XML Deserialization?

随声附和 提交于 2019-11-27 15:00:35
Julien Lebosquain

There's no equivalent of OnDeserialized for XML deserialization.

See this post for workarounds: How do you find out when you've been loaded via XML Serialization?

Marc Gravell

The only way you could do that in a graceful way is to manually implement IXmlSerializable, which is not fun. Simply; XmlSerializer doesn't support serialization callbacks.

Sometimes, though, you can switch to DataContractSerializer, which still offers xml capabilities but which does support serialization callbacks. Unfortunately the xml options are limited - it won't work for you xml structure, since that uses attributes (DataContractSerializer only supports elements).

You might also look at the comments on this answer, which discusses the points from this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!