DataRow的序列化问题在.net里,DataRow类型的对象是不支持序列化的,那么如果在一个需要序列化的对象中含有DataRow类型的字段该怎么办呢?呵呵,幸好Datatable是支持序列化的。因此,我们可以自定义序列化的行为,并在序列化和反序列化的时候用Datatable来对DataRow进行包装和解包。
DataRow的序列化问题为了自定义序列化行为,必须实现ISerializable接口。实现这个接口要实现 GetObjectData 方法以及在反序列化对象时使用的特殊构造函数。前者的作用是把该对象要封装的数据加入到系统提供的一个容器中,然后系统会对这些数据进行序列化;后者的作用是把反序列化的数据从容器中取出来,然后显式的赋值给该对象的某一个字段。
DataRow的序列化问题如下例所示,应当注意的代码用黑体标出。
DataRow的序列化问题
DataRow的序列化问题
using System;
DataRow的序列化问题
using System.Data;
DataRow的序列化问题
using System.Runtime.Serialization.Formatters.Binary;
DataRow的序列化问题
using System.Runtime.Serialization;
DataRow的序列化问题
using System.IO;
DataRow的序列化问题
using System.Security.Permissions;
DataRow的序列化问题
DataRow的序列化问题
namespace phenix.Dl

相关文章: