public void ReadXml(XmlReader reader)
        {
            // Cast the Data back from the Abstract Type.
            string typeAttrib = reader.GetAttribute("xsi:type");

#if DEBUG
            if (typeAttrib == null || !MyObjectBuilderSerializer.IsSerializerAvailable(typeAttrib))
#else
            if (typeAttrib == null)
#endif
            {
                typeAttrib = MyObjectBuilderSerializer.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 = MyObjectBuilderSerializer.GetSerializer(typeAttrib);
                this.Data = (TAbstractBase)serializer.Deserialize(customReader);

                customReader.Release();
                ReaderPool.Deallocate(customReader);
            }
        }
Esempio n. 2
0
        protected object Deserialize(XmlReader reader, XmlSerializer serializer, string customRootName)
        {
            CustomRootReader customReader;

            ReaderPool.AllocateOrCreate(out customReader);
            customReader.Init(customRootName, reader);

            var deserialized = serializer.Deserialize(customReader);

            customReader.Release();
            ReaderPool.Deallocate(customReader);

            return(deserialized);
        }
        public void ReadXml(XmlReader reader)
        {
            // Cast the Data back from the Abstract Type.
            string typeAttrib = reader.GetAttribute("xsi:type");

            if (typeAttrib == null)
            {
                typeAttrib = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.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 = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.GetSerializer(typeAttrib);
                this.Data = (TAbstractBase)serializer.Deserialize(customReader);

                customReader.Release();
                ReaderPool.Deallocate(customReader);
            }
        }