can every object be serialized even with referenced object within in a complex scenario

T

Tony Johansson

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
 
W

Willem van Rumpt

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.
 
A

Arne Vajhøj

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 ?

If all of that stuff is serializable then yes else no.
My second question: Does it exist object that can't be serialized ?

Yes. Open files, open network connections, open database connections
are common examples.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top