继承Region,实现iSerializable接口

解决方案 »

  1.   

    但是我不知道Region内部的数据结构!
    还望高手进一步指导!
      

  2.   

    大概是这样的:
    public class SerializableRegion:ISerializable
    {
    private Region _region=null;
    public SerializableRegion(Region region)
    {
    if(region==null)
    throw new ArgumentNullException();
    }
    public Region Region
    {
    get{return this._region;}
    }
    public SerializableRegion (SerializationInfo info, StreamingContext context) 
    {
    byte[] bytes=(byte[])info.GetValue("Data",typeof(byte[]));
    ConstructorInfo constructInfor=typeof(RegionData).GetConstructor(new Type[]{typeof(byte[])});
    RegionData data=(RegionData)constructInfor.Invoke(new object[]{bytes});
    this._region=new Region(data);
    }
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
    RegionData data=this.Region.GetRegionData();
    info.AddValue("Data",data.Data);
    }
    }