/// <summary> /// Deserialize the xml file represented by the inputted path and return it casted to the type T /// </summary> /// <typeparam name="T"></typeparam> /// <param name="xmlFilePath"></param> /// <returns></returns> public static T Deserialize <T>(string xmlFilePath) { // Create and load the XML document. XDocument doc = null; try { doc = XDocument.Load(xmlFilePath); } catch { DebugUtils.Fail("There was a problem loading the XML file with path " + xmlFilePath); return(default(T)); } // Create an XmlReader using the XML document. XmlReader nodeReader = doc.CreateReader(); // Move to the XnaContent element - this is to support backwards compatibility with our existing data files // One day we may run a script to change them all Debug.Assert(nodeReader.ReadToDescendant("XnaContent"), "No XnaContent element found as root tag"); // Now move to the Asset element - this contains the name of the type we are trying to load Debug.Assert(nodeReader.ReadToDescendant("Asset"), "No Asset element found"); // Obtain the Type attribute so we can reflectively work out the type string dataType = nodeReader.GetAttribute("Type"); // Get the assembly for the type we are trying to load - this has to pass Assembly assembly; Debug.Assert(TryGetAssembly(ref dataType, out assembly)); // Move either to the </Asset> tag if we have no data to load, or to the first data element nodeReader.Read(); // Load the type return(ReadType <T>(nodeReader, assembly, dataType)); }