什么架构使用system.runtime.serialization.ISerialized?

发布于 2024-11-06 02:41:39 字数 208 浏览 1 评论 0原文

我确实有一些类实现了自己的序列化/反序列化,但我在执行所有这些操作时没有实现 system.runtime.serialization.ISerialized。所以我的问题是使用 system.runtime.serialization.ISerialized 到底有什么好处?

在什么情况下我们需要实现system.runtime.serialization.ISerialized?

I do have some classes that implement their own serialization/deserialization but I'm doing all of these without implementing system.runtime.serialization.ISerializable. so my question is what exactly is the benefit of using system.runtime.serialization.ISerializable ?

in what example situation will we need to implement system.runtime.serialization.ISerializable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新人笑 2024-11-13 02:41:39

您的序列化不与标准 .net 序列化机制集成。您不能将其与 BinaryFormatter 一起使用。 ISerialized 使得 a) 控制序列化 b) 将其集成到二进制序列化的标准机制中成为可能。

另外,您决定编写自己的序列化也很奇怪。编写高效的生产质量序列化是相当昂贵的,特别是当.net中有可供使用的二进制和XML序列化以及一些很酷的第三方序列化(例如Protobuf和Thrift)时。

实际上,ISerialized 页面 上给出了很好的示例MSDN。

当您想要连接二进制序列化时,一个现实生活中的例子是它在序列化 DateTime 时丢失时区。 (至少在.net 2.0中)

You serialization doesn't integrate with standard .net serialization mechanisms. You can't use it with BinaryFormatter. ISerializable makes possible to a) control serialization b) integrate it into standard mechanism of binary serialization.

Also it is very strange that you decided to write your own serialization. This is rather expensive to write efficient production quality serialization, especially when there are binary and XML serializations ready to use in .net and couple of cool 3rd party ones, like Protobuf and Thrift.

Great example is actually given at ISerializable page on MSDN.

One real life example when you would want to hook into binary serialization is that it looses timezones when serializing DateTime. (At least in .net 2.0)

隐诗 2024-11-13 02:41:39

当您需要保存比仅序列化字段更复杂的数据时,BinaryFormatter 会使用 ISerialized - 例如,您想要以不同的方式处理数据(可能是压缩的 - 例如,字典在内存中相当大,但可以只是线路上的键/值列表)。同样的“链表” - 您将再次希望在一个对象(列表)的序列化中迭代该对象,而不仅仅是序列化第一个节点,并让该节点序列化自身和下一个节点, ETC。

ISerializable is used by BinaryFormatter when you need to persist data that is a bit more complex than just serializing the fields - for example, you want to process the data differently (maybe condensed - for example, a dictionary is pretty expansive in memory, but can just be a key/value list on the wire). Likewise a "linked list" - you would again want to iterate that in the serialization of one object (the list), rather than just serialize the first node, and have that node serialize itself and the next node, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文