当一个对象派生自MarshalByRefObject的,也标记为[Serializable接口]会发生什么? [英] what happens when an object derives from MarshalByRefObject and is also marked [Serializable]?

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

问题描述

我的工作我使用的AppDomain第一个项目,我不知道会发生什么,当一个对象派生自MarshalByRefObject的,也标记为[Serializable接口]

例如:

  [Serializable接口]
公共类DummyClass:MarshalByRefObject的
{

}
 

解决方案

它被引用编组,但仍然可以序列化等使用情况进行序列化。这里有一个执行细节这是足够有趣的是值得注意的:即连载用于远程格式化使用 SurrogateSelector ,这将产生一个代理的任何 MarshalByRefObject的它串行化,因此连载仍然会参照导致编组。其它序列化的用途将不会有 SurrogateSelector ,因此不会有这种效果。

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
{

}

解决方案

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天全站免登陆