views:

90

answers:

0

The followings are my code:

Code for serialization:

using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

public class Serializer
{
   public Serializer()
   {
   }

   public void SerializeObject(string filename, ObjectToSerialize objectToSerialize)
   {
      Stream stream = File.Open(filename, FileMode.Create);
      BinaryFormatter bFormatter = new BinaryFormatter();
      bFormatter.Serialize(stream, objectToSerialize);
      stream.Close();
   }

   public ObjectToSerialize DeSerializeObject(string filename)
   {
      ObjectToSerialize objectToSerialize;
      Stream stream = File.Open(filename, FileMode.Open);
      BinaryFormatter bFormatter = new BinaryFormatter();
      objectToSerialize = (ObjectToSerialize)bFormatter.Deserialize(stream);
      stream.Close();
      return objectToSerialize;
   }
}

My class

[Serializable()]  
public class Sheet : ISerializable  
{  
    //Some other properties for a sheet shuch as width, length, x, y 

    //An observable list is used to store all sub-sheets in a sheet 
    private SheetStack subSheets;

    public SheetStack SubSheets
    {
        get {return this.subSheets;}
        set {this.subSheets = value;}
    }

    public Sheet(SerializationInfo info, StreamingContext ctxt)  
    {  
        this.subSheets = (SheetStack)info.GetValue("SubSheets", typeof(SheetStack));
    }  

    public void GetObjectData(SerializationInfo info, StreamingContext ctxt)  
    {  
        info.AddValue("SubSheets", this.subSheets);
    }
}

[Serializable()]  
public class  SheetStack : ObservableCollection<Sheet>, ISerializable
{
    //No real properties for a sheet stack but some methods
    //Such as:
    //PopOneSheet( )
    //PushOneSheet( )
    //RotateAllSheets()
}

My problem is how to implement ISerializable for the class SheetStack so that Sheet.SubSheets can be correctly serialized and de-serialized.

Thank you very much.