gpt4 book ai didi

c# - ISerializable.GetObjectData 的反序列化等价物是什么?

转载 作者:太空狗 更新时间:2023-10-29 23:15:50 25 4
gpt4 key购买 nike

我正在编写自定义序列化程序,我刚刚完成了用于处理 ISerializable.GetObjectData 的部分的实现。但是当我去反序列化信息并将其重新应用于图形时,我没有看到 Set-ObjectData 的等效函数。

如何将 SerializationInfo 数据重新应用到图表中?

最佳答案

按照 ISerializable 的 MSDN 库文档中的描述实现特殊的反序列化构造函数:

The ISerializable interface implies a constructor with the signature constructor (SerializationInfo information, StreamingContext context). At deserialization time, the current constructor is called only after the data in the SerializationInfo has been deserialized by the formatter. In general, this constructor should be protected if the class is not sealed.

例如:

protected Widget(SerializationInfo info, StreamingContext context)
{
// Perform your deserialization here...
this.SerialNumber = (string)info.GetValue("SerialNumber", typeof(string));
}

关于c# - ISerializable.GetObjectData 的反序列化等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16363399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com