public IType Read(BinaryReader reader, out string name)
        {
            IType type = null;
            int length = reader.ReadInt32();
            long startPos = reader.BaseStream.Position;
            string readName = reader.ReadLpString();
            int typeId = reader.ReadInt32();
            int num = reader.ReadInt32();
            int unknown = reader.ReadInt32();

            type = TypeFactory.Create(typeId, num);
            type.Read(reader);
            long endPos = reader.BaseStream.Position;

            long amountRead = endPos - startPos;
            if (amountRead > length)
            {
                throw new ApplicationException("Read too much");
            }
            else if (amountRead < length)
            {
                throw new ApplicationException("Read too little");
            }

            name = readName;
            return type;
        }
        public IList<string> Read(BinaryReader reader)
        {
            IList<string> materials = new List<string>();

            int numMaterials = reader.ReadInt32();
            for (int i=0; i<numMaterials; i++)
            {
                materials.Add(reader.ReadLpString());
            }

            return materials;
        }
        public void BinaryReader_ReadLpString()
        {
            byte[] writtenData = { 0x0B, 0x00, 0x00, 0x00, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64 };

            string readStr;
            using (var stream = new MemoryStream(writtenData))
            {
                using (var reader = new BinaryReader(stream))
                {
                    readStr = reader.ReadLpString();
                }
            }

            Assert.AreEqual("hello world", readStr);
        }
        public void Read(BinaryReader reader)
        {
            bool hasLayers = reader.ReadInt32AsBoolean();
            if (hasLayers)
            {
                int layerDeclarationPosition = (int)reader.BaseStream.Position;
                int layerDeclaration = reader.ReadInt32();
                if (layerDeclaration != LayerDeclaration)
                {
                    var msg = String.Format(Resources.InvalidLayerMasksDeclaration, layerDeclarationPosition, layerDeclaration, LayerDeclaration);
                    throw new EntityException(msg);
                }

                int numLayerMasks = reader.ReadInt32();
                LayerMasks = new uint[numLayerMasks];
                for (int i = 0; i < LayerMasks.Length; i++)
                {
                    LayerMasks[i] = reader.ReadUInt32();
                }
            }

            GroupId = reader.ReadInt32();
            EntityName = reader.ReadLpString();

            int? fieldDeclaration = null;

            while (reader.BaseStream.Position <= reader.BaseStream.Length - 4 && (fieldDeclaration = reader.ReadInt32()) == NewAttributeDeclaration)
            {
                string name;
                IType type = TypeSerializer.Read(reader, out name);
                Fields[name] = type;
            }

            if (fieldDeclaration != null && fieldDeclaration != NewAttributeDeclaration)
            {
                reader.BaseStream.Seek(-4, SeekOrigin.Current);
            }
        }