当一个对象从 MarshalByRefObject 派生并且也被标记为 [Serializable] 时会发生什么? [英] what happens when an object derives from MarshalByRefObject and is also marked [Serializable]?

查看:25
本文介绍了当一个对象从 MarshalByRefObject 派生并且也被标记为 [Serializable] 时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我的第一个使用 AppDomains 的项目,我想知道当一个对象从 MarshalByRefObject 派生并标记为 [Serializable] 时会发生什么?

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]?

例如:

[Serializable]
public class DummyClass: MarshalByRefObject
{

}

推荐答案

它通过引用进行编组,但仍然可以为其他用例进行序列化以进行序列化.有一个实现细节很有趣,值得一提:为远程处理序列化的格式化程序使用 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 any MarshalByRefObject it serialises, hence serialising will still result in marshalling by reference. Other serialisation uses won't have that SurrogateSelector and so won't have that effect.

这篇关于当一个对象从 MarshalByRefObject 派生并且也被标记为 [Serializable] 时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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