Example #1
0
        // creates a list of field values from the given type.
        // stream needs to be positioned at the beginning of the entry.
        private DBRow ReadFields(BinaryReader reader, TypeInfo ttype, bool skipHeader = true)
        {
            if (!skipHeader)
            {
                readHeader(reader);
            }
            List <FieldInstance> entry = new List <FieldInstance>();

            for (int i = 0; i < ttype.Fields.Count; ++i)
            {
                FieldInfo field = ttype.Fields[i];

                FieldInstance instance = null;
                try {
                    instance = field.CreateInstance();
                    instance.Decode(reader);
                    entry.Add(instance);
                } catch (Exception x) {
                    throw new InvalidDataException(string.Format
                                                       ("Failed to read field {0}/{1}, type {3} ({2})", i, ttype.Fields.Count, x.Message, instance.Info.TypeName));
                }
            }
            DBRow result = new DBRow(ttype, entry);

            return(result);
        }
Example #2
0
        public override void Decode(BinaryReader reader)
        {
            contained.Clear();
            int itemCount = reader.ReadInt32();

            contained.Capacity = itemCount;
            for (int i = 0; i < itemCount; i++)
            {
                if (ContainerType.EncodeItemIndices)
                {
                    reader.ReadInt32();
                }
                List <FieldInstance> entry = new List <FieldInstance>(ContainerType.Infos.Count);
                foreach (FieldInfo info in ContainerType.Infos)
                {
                    FieldInstance field = info.CreateInstance();
                    field.Decode(reader);
                    entry.Add(field);
                }
                contained.Add(entry);
            }
        }