예제 #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);
        }
예제 #2
0
        public static string decodeSafe(FieldInfo d, BinaryReader reader)
        {
            string result = "failure";

            try {
                FieldInstance field = d.CreateInstance();
                field.Decode(reader);
                result = field.Value;
            } catch (Exception x) {
#if DEBUG
                // Console.WriteLine(x);
#endif
                result = x.Message.Replace("\n", "-");
            }
            return(result);
        }