serialization on static values

  • Thread starter Thread starter Deleo
  • Start date Start date
D

Deleo

Hello
Im having trouble serializing a static value inside an object and
deserialize it correctly.
Heres how it works

The idea is that i make lots of objects that has unique IDs, but each object
share one value and that is the ID of the last object created. This way i
know what the ID of the next object will be. So lets say 10 objects share
one value (static).
I create 10 objects and the static variable= 10. on all thos objects...

Now i serialize these objects inside a List<T>.
And close the application. Then i start the application and load in the
objects i serilized, but the problem is that the static value is reset, its
= 0....

That means that the static value did not serialize like the rest of the
objects.
How can i fix this? that my Shared value is saved.

When i load the 10 objects i want that share variable to be 10 and not 0.

thank you.
 
Remember, serialization is serializing instances of the objects. Static data
is not serialized because it's not instance data and there's really no way
to "automatically" do it.

Either store the count somewhere or after you load all the objects, set the
value to the highest ID.

Pete
 
Back
Top