2

I have around 50 classes in polymorphic, inheritance relation. I used XmlSerializer to serialize them. Now for few classes I want to implement IXmlSerializable. So I started for one of class.This class not base class but derived directly from base class of all polymorphic relation.

After implementation, resultant XML contains tags only for above class which I have written in WriteXML method. There is no information for other classes. Very strange behavior!!!!

So please guide me to solve this issue, so that other classes information would maintain.

  • Do you mean the information in the base class is not automatically serialized for your custom subclass? Or that other, non-related subclasses no longer serialize data at all? – Chris Sinclair Jun 12 '12 at 17:42
  • Which kind of information are you looking for `information for other classes`? – RredCat Jun 12 '12 at 17:53
  • Information for base class and for all other classes is not serialized at all.Resultant XML have tags only for class which I have implemented IXmlSerializable. – user1451825 Jun 12 '12 at 17:59
  • Information means public properties of classes. – user1451825 Jun 12 '12 at 18:00

2 Answers2

1

As I understand you correct - your xml contains properties that you implicit add in WriteXML (of current class)? But it is correct behavior. You should implicit add item as in example in description of interface.

If you need properties of base classes - add them. if you need properties of classes that inherit from this class - try to get them via reflection. Get Property Names using Reflection . But instead of typeof(MyClass) use .GetType() and check there how to get properties values.

Community
  • 1
  • 1
RredCat
  • 5,259
  • 5
  • 60
  • 100
0

Similar questions here and there.

End the ReadXml(XmlReader reader) method with the line

reader.Read();

seams to solves the problem...

Community
  • 1
  • 1
Sylvain B.
  • 719
  • 5
  • 31