Serializing private members of a class

G

Guest

I have a private instance of a object in a class i wish to include in the
output of class serialization. The object is private because the contents
cannot be modified outside the class but it is important that the contents of
this private member are retained when the class is serialised. Can anyone
tell me how i can include this private object instance into the serialised
output. I know there are a number of xmlattributes you can apply to classes
and class members, but i can't seem to find one that will allow me to do what
i want.

Thanks
 
B

Ben Lucas

The XmlSerializer does not support the serialization of private members. It
only serializes public fields and read/write properties.

In order to serialize a private member, you must use either a
BinaryFormatter or a SoapFormatter which can be found in the
System.Runtime.Serialization.Formatters.Binary or
System.Runtime.Serialization.Formatters.Soap namespaces, respectively.
 

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