コード例 #1
0
ファイル: SRZoneObject.cs プロジェクト: clarosa/SRZoneTools
 /// <summary>
 /// Reads the contents of a data block from an XML document.
 /// </summary>
 /// <param name="thisNode">XML node which represents an instance of this data block.</param>
 /// <param name="index">Index within a sequence (starts at 0).</param>
 public void ReadXml(XmlNode thisNode, int index)
 {
     try
     {
         SRXmlNodeReader reader = new SRXmlNodeReader(thisNode);
         name = reader.ReadString("name");
         if (name == "") name = null;
         handleOffset = reader.ReadUInt64("handle");
         parentHandleOffset = reader.ReadUInt64("parent_handle");
         objectTypeHash = reader.ReadInt32("object_type_hash");
         padding = reader.ReadUInt16("padding");
         XmlNodeList propertyNodes = reader.Node.SelectNodes("./properties/" + SRZoneProperty.XmlTagName);
         propertyList = new List<SRZoneProperty>(propertyNodes.Count);
         for (int i = 0; i < propertyNodes.Count; i++)
             propertyList.Add(SRZoneProperty.Create(propertyNodes[i], i));
     }
     catch (Exception e)
     {
         // Add context information for the error message
         if (index >= 0)
             e.Data[BlockName] = index + 1;
         throw;
     }
 }
コード例 #2
0
ファイル: SRZoneProperty.cs プロジェクト: clarosa/SRZoneTools
        /// <summary>
        /// Reads a property from an XML document and creates a new property object containing the data.
        /// The returned property will be an instance of one of the concrete derived property classes.
        /// </summary>
        /// <param name="thisNode">XML node which represents an instance of this data block.</param>
        /// <param name="index">Index within a sequence (starts at 0).</param>
        /// <returns>The new zone property which was read from the input stream.</returns>
        public static SRZoneProperty Create(XmlNode parentNode, int index)
        {
            SRZoneProperty property;
            try
            {
                // Read the common header
                SRXmlNodeReader reader = new SRXmlNodeReader(parentNode);
                UInt16 type = reader.ReadUInt16("type");
                Int32 nameCrc = reader.ReadInt32("name_crc");

                // Create the appropriate derived class based on the header information
                if (SRRawDataBlock.HasRawXmlData(parentNode))
                    property = new SRZoneDataProperty(type, nameCrc);
                else
                    property = Create(type, nameCrc);

                // Read the class-specific data into the derived class
                property.ReadXmlData(SRXmlNodeReader.GetNode(parentNode, "value"));

                // Read the optional padding data
                XmlNode paddingNode = reader.GetNodeOptional("padding");
                if (paddingNode != null && SRRawDataBlock.HasRawXmlData(paddingNode))
                    property.paddingData = new SRRawDataBlock(paddingNode);
            }
            catch (Exception e)
            {
                // Add context information for the error message
                if (index >= 0)
                    e.Data[BlockName] = index + 1;
                throw;
            }
            return property;
        }