c# - Why is DataTable serializable? -
so here's simple test case:
[serializable] class base { } [serializable] class derived : base { } binaryformatter formatter = new binaryformatter(); formatter.serialize(stream, new derived()); nothing special here. if remove either of 'serializable' tags, binaryformatter yells @ because items aren't serializable. in theory then, serializing datatable shouldn't work either because base class datatable - 'marshalbyvaluecomponent- isn't marked serializeable either ('typeof(marshalbyvaluecomponent).isserializable returns 'false'). why binaryformatter ignore not other non-serializable types? (or why isn't marshalbyvaluecomponent marked serializeable begin with?)
the dataset class defined follows:
[serializableattribute] public class dataset : marshalbyvaluecomponent, ilistsource, ixmlserializable, isupportinitializenotification, isupportinitialize, iserializable see: http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx
as can see there implementation of iserializable interface. interface allows object control own serialization , deserialization.
Comments
Post a Comment