开发者

what architecture make use of system.runtime.serialization.ISerializable?

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.开发者_如何学Goserialization.ISerializable?


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜