为什么你必须标记与属性[可序列化]一类? [英] Why do you have to mark a class with the attribute [serializable]?

查看:116
本文介绍了为什么你必须标记与属性[可序列化]一类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看到,因为你可以将任何文档转换为字节数组,并将其保存到磁盘,然后将该文件重建原来的样子(只要你有它的文件名等元数据)。

Seeing as you can convert any document to a byte array and save it to disk, and then rebuild the file to its original form (as long as you have meta data for its filename etc.).

为什么你必须标记与 A类[Serializable接口] 等?是一样的想法,元数据类型的信息,所以当你把对象其类的东西都正确映射?

Why do you have to mark a class with [Serializable] etc? Is that just the same idea, "meta data" type information so when you cast the object to its class things are mapped properly?

推荐答案

首先,你不这样做的有无的到。

First off, you don't have to.

这是一个简单的标记接口告诉该班是由项目的序列化程序它可以序列(其可以是或可以不是真),这是可以使用默认序列化。

It is simply a marker interface that tells the serializer that the class is composed of items that it can serialize (which may or may not be true) and that is can use the default serialization.

的XMLSerializer 有额外的要求有一个零参数的构造函数的类。

The XMLSerializer has the additional requirement to have a zero parameter constructor to the class.

有使用序列化合同(如<其它串行一href=\"http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx\"相对=nofollow> 的DataContractSerializer ) - 他们给你了序列化的更多的控制不是简单地标志着类序列化。您也可以通过执行 <$ C $获得更多的控制权C> ISerializable的 接口。

There are other serializers that use contracts for serialization (such as the DataContractSerializer) - they give you more control over serialization than simply marking a class as Serializable. You can also get more control by implementing the ISerializable interface.

这篇关于为什么你必须标记与属性[可序列化]一类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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