public void ReadXml(XmlReader reader) { // Cast the Data back from the Abstract Type. string typeAttrib = reader.GetAttribute("xsi:type"); //#if DEBUG if (typeAttrib == null || !MyXmlSerializerManager.IsSerializerAvailable(typeAttrib)) //#else // if (typeAttrib == null) //#endif { typeAttrib = MyXmlSerializerManager.GetSerializedName(typeof(TAbstractBase)); } // Read the Data, Deserializing based on the (now known) concrete type. { CustomRootReader customReader; ReaderPool.AllocateOrCreate(out customReader); customReader.Init(typeAttrib, reader); var serializer = MyXmlSerializerManager.GetSerializer(typeAttrib); this.Data = (TAbstractBase)serializer.Deserialize(customReader); customReader.Release(); ReaderPool.Deallocate(customReader); } }
public void WriteXml(XmlWriter writer) { Type type = m_data.GetType(); { CustomRootWriter customWriter; WriterPool.AllocateOrCreate(out customWriter); var derivedName = MyXmlSerializerManager.GetSerializedName(type); customWriter.Init(derivedName, writer); MyXmlSerializerManager.GetSerializer(type).Serialize(customWriter, m_data); customWriter.Release(); WriterPool.Deallocate(customWriter); } }