public void XmlDeserialize(Stream s) { var doc = new XmlDocument(); doc.Load(s); var root = doc.DocumentElement; if (root != null) { Console.WriteLine(root.Attributes); var verStr = "0"; foreach (XmlNode node in doc.ChildNodes) { if (node.Name != "dsc") { continue; } verStr = node.Attributes["version"].Value; break; } if (verStr == "0") { Console.WriteLine("Note: Couldn't find the xml file's ver"); } verStr = "302121504"; Console.WriteLine(verStr); var ver = int.Parse(verStr); s.Position = 0; XmlSerializer serializer; switch (ver) { case 0x12020220: serializer = new XmlSerializer(typeof(DscFile)); File = serializer.Deserialize(s) as DscFile; break; case 0x43535650: serializer = new XmlSerializer(typeof(F2DscFile)); File = serializer.Deserialize(s) as F2DscFile; break; default: throw new XmlException("document doesn't contain valid version"); } } }
public void Deserialize(Stream s, Endianness endianness, BinarySerializationContext context) { var magic = DataStream.ReadUInt32(s); s.Position -= 4; var serial = new BinarySerializer(); switch (magic) { case 302121504: File = serial.Deserialize(s, typeof(DscFile)) as DscFile; break; case 0x43535650: serial.Endianness = Endianness.Big; File = serial.Deserialize(s, typeof(F2DscFile)) as F2DscFile; break; default: throw new Exception("invalid dsc file"); } }