示例#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
 /**
  * <summary>Checks whether this DBFile contains a <see cref="DBRow"/> with equivalent data to a given DBRow.</summary>
  *
  * <param name="checkRow">The <see cref="DBRow"/> to be compared to this DBFile's rows.</param>
  * <returns>Whether the DBFile contains a DBRow with equivalent data to <paramref name="checkRow"/>.</returns>
  */
 public bool ContainsRow(DBRow checkRow)
 {
     foreach (DBRow row in Entries)
     {
         if (row.SameData(checkRow))
         {
             return(true);
         }
     }
     return(false);
 }
示例#3
0
 /**
  * <summary>Checks whether this DBRow has equivalent data to <paramref name="row"/>.</summary>
  * <remarks>This returns true if the data is equivalent even if the schemas aren't.  e.g.: A string with the same contents as a string_ascii will still allow this to evaluate to true instead of forcing a false value.</remarks>
  *
  * <param name="row">The DBRow for this row to be compared to.</param>
  * <returns>Whether the two DBRows have equivalent data.</returns>
  */
 public bool SameData(DBRow row)
 {
     if (Count != row.Count)
     {
         return(false);
     }
     for (int i = 0; i < Count; ++i)
     {
         if (!this[i].Value.Equals(row[i].Value))
         {
             return(false);
         }
     }
     return(true);
 }