Tony said:
Hi!
If I have an object A that reference B and object B reference C
and a lot of built-in types and some user defined struct will object A be
able to be serialized to a file ?
My second question: Does it exist object that can't be serialized ?
//Tony
To answer the second question (and with it hopefully the first):
Yes and no.
There are classes for which serialization doesn't have any meaning full
purpose, and presumably there are classes which don't support
serialization out of the box.
As an example of the former, take the System.Threading.Thread class. How
would you serialize a thread? What would you serialize?
But for non-serializable classes, by implementing ISerializable *you*
can define what state constitutes a serializaed instance. In essence,
you define a contract for serialization yourself. The serializability of
a class is then scoped to your own specific scenario, but it *is*
serializable within that scope.
As an example, and leaving usefulness aside, you could serialize a
thread as a complex of threadname, priority, and whether it's a
background thread or not. Upon deserialization you could spawn a new
thread using that information.