Exemplo n.º 1
0
 /// <summary>
 /// Read a header.
 /// </summary>
 /// <param name="r">The reader.</param>
 public abstract void Read(FileReader r);
Exemplo n.º 2
0
        /// <summary>
        /// Read the data.
        /// </summary>
        /// <param name="r">The reader.</param>
        public void ReadData(FileReader r)
        {
            //Set back position.
            long bak = r.Position;

            //Valid.
            if (Offset != 0 && Offset != -1)
            {
                //Jump to reference.
                r.Position = (Absolute ? 0 : r.CurrentOffset) + Offset;

                //Set current offset on jump.
                if (SetCurrentOffsetOnJump())
                {
                    r.StructureOffsets.Push(r.CurrentOffset);
                    r.CurrentOffset = r.Position;
                }

                //Identifier.
                T obj;
                if (DataTypes.Count > 0)
                {
                    Type type = Identifier < DataTypes.Count ? DataTypes[Identifier] : null;
                    if (type != null)
                    {
                        obj = (T)Activator.CreateInstance(type);
                    }
                    else
                    {
                        obj = default(T);
                    }
                }
                else
                {
                    obj = Activator.CreateInstance <T>();
                }

                //Data.
                if (obj != null)
                {
                    //Read data.
                    if (obj as IOFile != null)
                    {
                        FileReader r2 = new FileReader(r.BaseStream);
                        r2.Position = r.Position;
                        ((IReadable)obj).Read(r2);
                        r.Position = r2.Position;
                    }
                    else
                    {
                        ((IReadable)obj).Read(r);
                    }
                }

                //Restore current offset.
                if (SetCurrentOffsetOnJump())
                {
                    r.CurrentOffset = r.StructureOffsets.Pop();
                }

                //Set position.
                r.Position = bak;

                //Return the data.
                Data = obj;
            }

            //Invalid.
            else
            {
                Data = default(T);
            }
        }