Ejemplo n.º 1
0
 // FACTORY METHODS (STATIC)
 /// <summary>
 /// Creates a new Property item of the specified derived type.
 /// The item will initially have default data.
 /// </summary>
 /// <param name="binaryReader"></param>
 /// <returns></returns>
 public static SRZoneProperty Create(UInt16 type, Int32 nameCrc)
 {
     SRZoneProperty property;
     if (OptionParseValues)
     {
         switch (type)
         {
             case StringType:
                 property = new SRZoneStringProperty(nameCrc); break;
             case DataType:
                 property = new SRZoneDataProperty(type, nameCrc); break;
             case TransformType:
                 property = new SRZoneTransformProperty(nameCrc); break;
             case TransformOrientationType:
                 property = new SRZoneTransformOrientationProperty(nameCrc); break;
             default:
                 throw new SRZoneFileException("Unknown property type (" + type.ToString() + ").");
         }
     }
     else
         property = new SRZoneDataProperty(type, nameCrc);
     return property;
 }
Ejemplo n.º 2
0
        /// <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;
        }