It seems like I can serialize classes that don't have that interface, so I am unclear on its purpose.
ISerializable
is used to provide custom binary serialization, usually for BinaryFormatter
(and perhaps for remoting purposes). Without it, it uses the fields, which can be:
[NonSerialized]
)By implementing ISerializable
you can provide your own binary serialization mechanism. Note that the xml equivalent of this is IXmlSerializable
, as used by XmlSerializer
etc.
For DTO purposes, BinaryFormatter
should be avoided - things like xml (via XmlSerializer
or DataContractSerializer
) or json are good, as are cross-platform formats like protocol buffers.
For completeness, protobuf-net does include hooks for ISerializable
(allowing you to use a portable binary format without writing lots of code), but BinaryFormatter
wouldn't be your first choice here anyway.