Esempio n. 1
0
        public static T Deserialize <T>(XmlReader input, string referenceRelocationPath)
        {
            var serializer = new IntermediateSerializer();
            var reader     = new IntermediateReader(serializer, input, referenceRelocationPath);

            if (!reader.MoveToElement("XnaContent"))
            {
                throw new InvalidContentException(string.Format("Could not find XnaContent element in '{0}'.", referenceRelocationPath));
            }

            // Initialize the namespace lookups from
            // the attributes on the XnaContent element.
            serializer.CreateNamespaceLookup(input);

            // Move past the XnaContent.
            input.ReadStartElement();

            // Read the asset.
            var format = new ContentSerializerAttribute {
                ElementName = "Asset"
            };
            var asset = reader.ReadObject <T>(format);

            // TODO: Read the shared resources and external
            // references here!

            // Move past the closing XnaContent element.
            input.ReadEndElement();

            return(asset);
        }
Esempio n. 2
0
        public static T Deserialize <T>(XmlReader input, string referenceRelocationPath)
        {
            var serializer = new IntermediateSerializer();
            var reader     = new IntermediateReader(serializer, input, referenceRelocationPath);
            var asset      = default(T);

            try
            {
                if (!reader.MoveToElement("XnaContent"))
                {
                    throw new InvalidContentException(string.Format("Could not find XnaContent element in '{0}'.",
                                                                    referenceRelocationPath));
                }

                // Initialize the namespace lookups from
                // the attributes on the XnaContent element.
                serializer.CreateNamespaceLookup(input);

                // Move past the XnaContent.
                input.ReadStartElement();

                // Read the asset.
                var format = new ContentSerializerAttribute {
                    ElementName = "Asset"
                };
                asset = reader.ReadObject <T>(format);

                // Process the shared resources and external references.
                reader.ReadSharedResources();
                reader.ReadExternalReferences();

                // Move past the closing XnaContent element.
                input.ReadEndElement();
            }
            catch (XmlException xmlException)
            {
                throw reader.NewInvalidContentException(xmlException, "An error occured parsing.");
            }

            return(asset);
        }