4

I have an MDI application with a treeview control docked to the left and five classes containing the information of the tree nodes i.e Editors for that kind of node.

  • How should I serialize the application such that all the objects are serialized into a single binary file?

  • How to store my resources in it so a single file can be sent to all the machines?

Thanks.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91

1 Answers1

7

If you wish to serialize multiple objects into one file, just simply combine them all into one object.

For example, you have a lot of objects need to serialize like these:

Teacher t = new Teacher();

Student[] students = new Student[] { ... };

Tool blackboard = new Tool();

...

And all of these objects should be serializable.

You can create a container to contain those object, and serialize it.

[Serializable]
class School
{
    Teacher t;

    Student[] students;

    Tool blackboard;
}

Now, you just need to serialize the school object into one binary file.

J.C
  • 633
  • 1
  • 13
  • 27
  • Two doubts though. 1. doesn't the objects in the container class needs the serializable attribute? 2. Can I store files as byte arrays in a list? – Sri Harsha Chilakapati Mar 28 '13 at 07:25
  • @SriHarshaChilakapati: First, no. However, if you wish to handle every detail of serialization, you can consider to implement the ISerializable interface. Second, do you mean you want to read a file as bytes? Try the [FileStream](http://msdn.microsoft.com/en-us/library/system.io.filestream.read.aspx) – J.C Mar 28 '13 at 07:45