c# - [Serializable] 属性有哪些 ISerializable 没有的功能?

标签 c# .net serialization

<分区>

Possible Duplicate:
What's the difference between using the Serializable attribute & implementing ISerializable?

标记 class 有什么作用?与 Serializable做?例如:

[Serializable]
public Hashtable 
{
}

它与 class 有何不同?实现 ISerializable ?例如:

public Hashtable : ISerializable
{
}

与标记 class 有何不同?作为Serializable并实现 ISerializable ?例如:

[Serializable]
public Hashtable : ISerializable
{
}

[Serializable] 相对于 ISerializable 的目的是什么?

tl;dr:什么是[Serializable]

最佳答案

我以为你会链接到 Serializable ,但你没有:

All the public and private fields in a type that are marked by the SerializableAttribute are serialized by default, unless the type implements the ISerializable interface to override the serialization process.

和,

Apply the SerializableAttribute attribute even if the class also implements the ISerializable interface [...]

Serializable 属性表示该类型可以被序列化。 ISerializable 表示该类型想要控制如何该类型被序列化。


或者,换句话说,您的问题措辞不当。 SerializableAttribute始终 应用于(可序列化的类),并且是序列化的“基本”级别。 ISerializable 添加了更多内容(通过允许您编写代码来控制进程)。

关于c# - [Serializable] 属性有哪些 ISerializable 没有的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8594957/

相关文章:

c# - Windows 8 Metro 应用程序 - 渲染 PNG

c# - C# 中的实数舍入不一致

c# - Resharper 将自动属性转换为完整属性

c# - 为什么 Any 比 Contains 慢?

c# - 如何修复 WinForms 窗体中的闪烁?

c# - Azure Blob 存储 - 上传速度非常慢

c# - In 和 Out 属性在 .NET 中如何工作?

python - 具有 unique_together 约束的 django rest 序列化程序中的 read_only 字段

c# - DataContract 序列化 - 基类、继承和覆盖

c# - 关闭\销毁异步方法中的 Activity