Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. deserialization problem

deserialization problem

Scheduled Pinned Locked Moved C#
questionhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cyn8
    wrote on last edited by
    #1

    Hi there, if i got an 3 arraylist to be serialize, each with different type(Point[] or int) how do i deserialize them back to the 3 different arraylist accordingly. Should i save the number of items in each of the arraylist? Check the type? What other methods would u suggest? Thanks in advance.

    T 1 Reply Last reply
    0
    • C cyn8

      Hi there, if i got an 3 arraylist to be serialize, each with different type(Point[] or int) how do i deserialize them back to the 3 different arraylist accordingly. Should i save the number of items in each of the arraylist? Check the type? What other methods would u suggest? Thanks in advance.

      T Offline
      T Offline
      Tormod Fjeldskaar
      wrote on last edited by
      #2

      If you serialize the lists into separate streams, just remember which list resides in which stream and you'll be fine. If you serialize the lists into one common stream, though, make sure you deserialize them in the exact same order they were serialized.

      C 1 Reply Last reply
      0
      • T Tormod Fjeldskaar

        If you serialize the lists into separate streams, just remember which list resides in which stream and you'll be fine. If you serialize the lists into one common stream, though, make sure you deserialize them in the exact same order they were serialized.

        C Offline
        C Offline
        cyn8
        wrote on last edited by
        #3

        i need to save all the arraylists into a common arraylist and then serialize it because i want to save it into a file. Is this correct? Below is part of the code i wrote: In Save() ArrayList arr = new ArrayList(); arr.Add(Arraylist1);//arraylist containing Point[] for(int i=0;i { GraphicsPathData gpd = new GraphicsPathData((GraphicsPath)PathList[i]); Stream gpdStream = GraphicsPathData.Serialize(gpd); arr.Add(gpdStream); } arr.Add(Arraylist1);//arraylist containing enum formatter.Serialize(myStream, arr); myStream.Close(); in OpenFile() ArrayList arr =new ArrayList(); if (openFileDialog.ShowDialog() == DialogResult.OK) { filename = openFileDialog.FileName; Stream myStream = openFileDialog.OpenFile(); if (myStream != null) { IFormatter formatter = new BinaryFormatter(); arr = (ArrayList) formatter.Deserialize(myStream); myStream.Close(); ................. However the problem here, how can i separate the arr into the correct arraylist? Thanks for your help

        T 1 Reply Last reply
        0
        • C cyn8

          i need to save all the arraylists into a common arraylist and then serialize it because i want to save it into a file. Is this correct? Below is part of the code i wrote: In Save() ArrayList arr = new ArrayList(); arr.Add(Arraylist1);//arraylist containing Point[] for(int i=0;i { GraphicsPathData gpd = new GraphicsPathData((GraphicsPath)PathList[i]); Stream gpdStream = GraphicsPathData.Serialize(gpd); arr.Add(gpdStream); } arr.Add(Arraylist1);//arraylist containing enum formatter.Serialize(myStream, arr); myStream.Close(); in OpenFile() ArrayList arr =new ArrayList(); if (openFileDialog.ShowDialog() == DialogResult.OK) { filename = openFileDialog.FileName; Stream myStream = openFileDialog.OpenFile(); if (myStream != null) { IFormatter formatter = new BinaryFormatter(); arr = (ArrayList) formatter.Deserialize(myStream); myStream.Close(); ................. However the problem here, how can i separate the arr into the correct arraylist? Thanks for your help

          T Offline
          T Offline
          Tormod Fjeldskaar
          wrote on last edited by
          #4

          You don't need a common arraylist to serialize several arraylists into one file. Just make several calls to formatter.Serialize passing the same stream:

          formatter.Serialize(myStream, arr1)
          formatter.Serialize(myStream, arr2)
          formatter.Serialize(myStream, arr3)

          To restore the arraylists, make the calls to formatter.Deserialize in the exact same order:

          arr1 = (ArrayList) formatter.Deserialize(myStream);
          arr2 = (ArrayList) formatter.Deserialize(myStream);
          arr3 = (ArrayList) formatter.Deserialize(myStream);

          C 1 Reply Last reply
          0
          • T Tormod Fjeldskaar

            You don't need a common arraylist to serialize several arraylists into one file. Just make several calls to formatter.Serialize passing the same stream:

            formatter.Serialize(myStream, arr1)
            formatter.Serialize(myStream, arr2)
            formatter.Serialize(myStream, arr3)

            To restore the arraylists, make the calls to formatter.Deserialize in the exact same order:

            arr1 = (ArrayList) formatter.Deserialize(myStream);
            arr2 = (ArrayList) formatter.Deserialize(myStream);
            arr3 = (ArrayList) formatter.Deserialize(myStream);

            C Offline
            C Offline
            cyn8
            wrote on last edited by
            #5

            hi there, Thanks for the reply. Your solution works perfectly for binary serialization. However, i was wondering, does this concept works the same if i want to use XML serialization? Thanks.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups