当一个对象派生自 MarshalByRefObject 并且也被标记为 [Serializable] 时,会发生什么?
我正在开发我的第一个使用 AppDomains 的项目,我想知道当一个对象派生自 MarshalByRefObject 并且也被标记为 [Serialized] 时会发生什么?
例如:
[Serializable]
public class DummyClass: MarshalByRefObject
{
}
I'm working on my first project that uses AppDomains and I'm wondering what happens when an object derives from MarshalByRefObject and is also marked [Serializable]?
for example:
[Serializable]
public class DummyClass: MarshalByRefObject
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它通过引用进行编组,但仍然可以针对其他序列化用例进行序列化。有一个非常有趣且值得注意的实现细节:为远程处理进行序列化的格式化程序使用
SurrogateSelector
,它将为其序列化的任何MarshalByRefObject
生成代理,因此,序列化仍然会导致通过引用进行编组。其他序列化用途不会有该SurrogateSelector
,因此不会产生这种效果。It gets marshalled by reference, but can still be serialised for other use-cases for serialisation. There's an implementation detail to this that is interesting enough to be worth noting: The formatter that is serialising for remoting uses a
SurrogateSelector
that will produce a proxy for anyMarshalByRefObject
it serialises, hence serialising will still result in marshalling by reference. Other serialisation uses won't have thatSurrogateSelector
and so won't have that effect.