F
films
I understand the concept.
Serialization of a class will add all the sub-objects of the class to
the stream if there are also serializible.
So say I have:
[Serialize]
class Author
{
public string Name = string.empty;
void Author(author)
{
Name = author;
}
}
[Serialize]
class Book
{
public Author author = null;
void Book(string authorname)
{
author = new Author(authorname);
}
}
void Main()
{
Book mybook = new book("John Smith");
// here I would open a stream and serialize the book collection.
}
Now, when I read back the stream and populate the book collection there
is indeed a reference to the author, since it saved the information,
however, what if I tried this:
void Main()
{
Book mybook = new book("John Smith");
Book mybook2 = mybook;
// here I would open a stream and serialize the book collection.
// then I read back both books, which should both contain a ref
// to the single author entry.
}
upon reading back the books from the stream there are TWO copies of
Author, not just a reference to the single entry I started with
So, if I change the author name on one book, it will not update the
second book.
Is there a way to have the object's runtime references persist between
sessions given that they are saved/serialized to a stream and read
back?
It would seem that the serialization process copies each object
reference by value to the stream when serializing. Is there a work
around or is this something beyond the capabilites of serialization?
Serialization of a class will add all the sub-objects of the class to
the stream if there are also serializible.
So say I have:
[Serialize]
class Author
{
public string Name = string.empty;
void Author(author)
{
Name = author;
}
}
[Serialize]
class Book
{
public Author author = null;
void Book(string authorname)
{
author = new Author(authorname);
}
}
void Main()
{
Book mybook = new book("John Smith");
// here I would open a stream and serialize the book collection.
}
Now, when I read back the stream and populate the book collection there
is indeed a reference to the author, since it saved the information,
however, what if I tried this:
void Main()
{
Book mybook = new book("John Smith");
Book mybook2 = mybook;
// here I would open a stream and serialize the book collection.
// then I read back both books, which should both contain a ref
// to the single author entry.
}
upon reading back the books from the stream there are TWO copies of
Author, not just a reference to the single entry I started with
So, if I change the author name on one book, it will not update the
second book.
Is there a way to have the object's runtime references persist between
sessions given that they are saved/serialized to a stream and read
back?
It would seem that the serialization process copies each object
reference by value to the stream when serializing. Is there a work
around or is this something beyond the capabilites of serialization?