Serializing private members of a class

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top