Serialize an Interface Class

MarkMacrae

New member
Joined
Apr 19, 2006
Messages
1
Hi

Im trying to serialize an object to XML (c#) using the System.XMLSerializer but Im getting exceptions due to the class being an interface (see code snippet below).

string filename = @"C:\Mark\CODAAccount_" + myElement.Code + ".xml";
TextWriter tw = new StreamWriter(filename);
XmlSerializer serializer = new XmlSerializer(typeof(codaElementClass));
serializer.Serialize(tw,myElement);


I have read that there are ways I can implement the ISerializable interface which will allow me to serialize my object, but can anyone help me with this and provide some example syntax??

Thanks
Mark
 
The XmlSerializer class needs to know about the class data structures to be able to serialze it - interfaces do not have any data fields and therefore it cannot use them to determine storage requirements.

If you are looking at implementing ISerializable yourself then this MSDN article is a good starting point.
 
Back
Top