gpt4 book ai didi

c# - 为什么 ISerializationSurrogate.SetObject 返回一个对象并获取一个对象来填充?

转载 作者:太空狗 更新时间:2023-10-29 21:35:55 27 4
gpt4 key购买 nike

我最近在研究运行时序列化并遇到了 ISerializationSurrogate界面。我很困惑它是 SetObject然而方法。

签名是:

对象 SetObjectData(对象对象,System.Runtime.Serialization.SerializationInfo 信息,System.Runtime.Serialization.StreamingContext 上下文,System.Runtime.Serialization.ISurrogateSelector 选择器)

而帮助信息是:

Summary:

Populates the object using the information in the System.Runtime.Serialization.SerializationInfo.

Parameters:

obj: The object to populate.

info: The information to populate the object.

context: The source from which the object is deserialized.

selector: The surrogate selector where the search for a compatible surrogate begins.

Returns:

The populated deserialized object.

如果obj 是要填充的对象,为什么它会返回填充的反序列化对象?一合example他们从 MSDN 填充 objreturn null

最佳答案

查看此 .NET 专栏文章:http://msdn.microsoft.com/en-us/magazine/cc188950.aspx

它说:

Notice that the SetObjectData method has a return type of Object. This would make you think that SetObjectData could actually return a reference to a completely different type of object. However, the Microsoft SoapFormatter and BinaryFormatter types ignore this return value completely, which is why I returned null in the previous example. Obviously, there is a bug here; the return value should allow SetObjectData to return a different object.

Microsoft has scheduled this bug for repair. If the return value is null, then the formatter will use the object that it passed to SetObjectData. If SetObjectData returns an object reference, then the formatter will use the object that's returned. Unfortunately, until this bug is fixed, you can't deserialize a value type.

关于c# - 为什么 ISerializationSurrogate.SetObject 返回一个对象并获取一个对象来填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7723640/

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