Serializing the same object instance twice...
-
Hello, I have a collection of
ITask
(an interface I've created) objects. References to these objets are duplicated. They are kept in a second collection. This second collection is a collection of categories. Each category can contain child categories. Each task can appear only in one category. This means that every singleITask
object in theITask
collection is somewhere inside the categories. I'm using this implementation to allow the user to filter theITask
objects by categories, and by other means which are not relevant. OK... Now I want the tasks to be "restored" when the program next runs, so I serialize and deserialize them... So far so good... I want to serialize the collection of categories the user have created, and restore them too... I can serialize the categories collection as well, but what will happen to theITask
objects when I deserialize the categories? Will they point to the same objects deserialized to theITask
collection? Hope this is clear enough... :) If you have any other ideas regarding how to better store the collections, I'd be more than happy to hear them. :) Thanks in advance, Shy. -
Hello, I have a collection of
ITask
(an interface I've created) objects. References to these objets are duplicated. They are kept in a second collection. This second collection is a collection of categories. Each category can contain child categories. Each task can appear only in one category. This means that every singleITask
object in theITask
collection is somewhere inside the categories. I'm using this implementation to allow the user to filter theITask
objects by categories, and by other means which are not relevant. OK... Now I want the tasks to be "restored" when the program next runs, so I serialize and deserialize them... So far so good... I want to serialize the collection of categories the user have created, and restore them too... I can serialize the categories collection as well, but what will happen to theITask
objects when I deserialize the categories? Will they point to the same objects deserialized to theITask
collection? Hope this is clear enough... :) If you have any other ideas regarding how to better store the collections, I'd be more than happy to hear them. :) Thanks in advance, Shy.Hello,
shyagam wrote:
Will they point to the same objects deserialized to the ITask collection?
No, I don't think so. You will then have the double number of ITask objects! I would store one Collection and additionaly the way the second collection was sorted. After deserialization you fill the second Collection with the ITask objects of the first, and Sort it again! All the best, Martin -- modified at 6:39 Wednesday 20th June, 2007 The advantage of storing the way you are sorting (with an enum for ex.), is that you are allways consistend with updated programs in combination with old datas.
-
Hello, I have a collection of
ITask
(an interface I've created) objects. References to these objets are duplicated. They are kept in a second collection. This second collection is a collection of categories. Each category can contain child categories. Each task can appear only in one category. This means that every singleITask
object in theITask
collection is somewhere inside the categories. I'm using this implementation to allow the user to filter theITask
objects by categories, and by other means which are not relevant. OK... Now I want the tasks to be "restored" when the program next runs, so I serialize and deserialize them... So far so good... I want to serialize the collection of categories the user have created, and restore them too... I can serialize the categories collection as well, but what will happen to theITask
objects when I deserialize the categories? Will they point to the same objects deserialized to theITask
collection? Hope this is clear enough... :) If you have any other ideas regarding how to better store the collections, I'd be more than happy to hear them. :) Thanks in advance, Shy.Hello, if you serialize the collections using 2 Serialize() calls, you would end up with duplicates of each ITask object. I would do something like this (in C#):
[Serializable]
public class DataStore
{
public ICollection Tasks;
public ICollection Categories;
}Serializing this class will keep the references correct and will not produce duplicates. greetings, Enno Welbers
-
Hello, I have a collection of
ITask
(an interface I've created) objects. References to these objets are duplicated. They are kept in a second collection. This second collection is a collection of categories. Each category can contain child categories. Each task can appear only in one category. This means that every singleITask
object in theITask
collection is somewhere inside the categories. I'm using this implementation to allow the user to filter theITask
objects by categories, and by other means which are not relevant. OK... Now I want the tasks to be "restored" when the program next runs, so I serialize and deserialize them... So far so good... I want to serialize the collection of categories the user have created, and restore them too... I can serialize the categories collection as well, but what will happen to theITask
objects when I deserialize the categories? Will they point to the same objects deserialized to theITask
collection? Hope this is clear enough... :) If you have any other ideas regarding how to better store the collections, I'd be more than happy to hear them. :) Thanks in advance, Shy.